免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12345
最近访问板块 发新帖
楼主: 大血落弯刀
打印 上一主题 下一主题

[C] 含泪求助帮我改改C程序,提高处理数据效率 [复制链接]

论坛徽章:
2
技术图书徽章
日期:2013-09-04 15:21:51酉鸡
日期:2013-11-01 21:20:20
41 [报告]
发表于 2008-12-22 22:36 |只看该作者
lz是为了学习,而不是为了解决问题。所以......

论坛徽章:
0
42 [报告]
发表于 2008-12-23 11:08 |只看该作者
用python多好,几条语句就完成了。

论坛徽章:
0
43 [报告]
发表于 2008-12-23 11:34 |只看该作者
呵呵

ii.py

  1. #!/usr/bin/env python

  2. fd = open('Noname.txt')
  3. all = fd.read()
  4. fd.close()
  5. lst = all.split('\n')
  6. dit = {}
  7. for i in lst:
  8.         if dit.has_key(i):
  9.                 dit[i] = dit[i] + 1
  10.         else:
  11.                 dit[i] = 0
  12. for i in dit:
  13.         if dit[i] > 0:
  14.                 print dit[i], i.split('@')[0]
复制代码



  1. $ time ./ii.py > xx

  2. real        0m0.188s
  3. user        0m0.171s
  4. sys        0m0.017s
  5. [sliu@bogon tmp]$
复制代码

论坛徽章:
0
44 [报告]
发表于 2008-12-23 20:26 |只看该作者
dfsfsfsdf

论坛徽章:
0
45 [报告]
发表于 2008-12-24 03:16 |只看该作者
>基本上实现了功能,但由于我对C不太熟悉,
>在效率上还没有优化

>请各位高人帮我修改下程序

>能不能帮我优化下程序,使程序在最快的时间里按要求输出结果

use Perl could be shorter & faster than python's. But as you look at LZ's comments,
it is not what he/she want.

论坛徽章:
0
46 [报告]
发表于 2009-01-11 15:38 |只看该作者

回复 #1 大血落弯刀 的帖子

r=open('Noname.txt','rb')
s=r.readlines()
r.close()
ss=''
dis={}
for i in s:
i=i.replace('\r\n','')
if dis.has_key(i):
  dis+=1
else:
  dis=1
for j in dis.keys():
if dis[j]>1:
  ss+=str(dis[j])+' '+j.split('@')[0]+'\t'
   
w=open('w.txt','wb')
w.writelines(ss)
w.close()
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP