| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 850 人关注过本帖
标题:Count the lines of input files
只看楼主 加入收藏
redunkind
Rank: 2
等 级:论坛游民
帖 子:36
专家分:14
注 册:2011-4-10
结帖率:50%
收藏
已结贴  问题点数:15 回复次数:7 
Count the lines of input files
描述
The input file will contain an unknown number of lines with at most 1000 characters on each line. All the characters will be printable ASCII characters.
输入
The input file contains some lines.
Note that the input file will always exist, but may be empty.
输出
The number of lines in the input file.
样例输入
one
and two
three
样例输出
3
高手们这个该怎么做啊??没思路厄
搜索更多相关主题的帖子: contain always files number 
2011-07-11 13:30
laoyang103
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:内蒙古包头
等 级:贵宾
威 望:19
帖 子:3082
专家分:11056
注 册:2010-5-22
收藏
得分:5 
Chinese Please

                                         
===========深入<----------------->浅出============
2011-07-11 14:06
草狼
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:2
帖 子:577
专家分:1040
注 册:2010-4-6
收藏
得分:5 
int main(){
    int cont=0;
    char str[1009];
    while(~scanf("%s",str)){
        cont++;
    }
    printf("%d\n",cont);
    return 0;
}
2011-07-11 14:13
redunkind
Rank: 2
等 级:论坛游民
帖 子:36
专家分:14
注 册:2011-4-10
收藏
得分:0 
回复 3楼 草狼
为什么没输出的啊???什么时候才回输出那个结果啊?
2011-07-12 12:00
succubus
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:4
帖 子:635
专家分:1080
注 册:2007-10-7
收藏
得分:5 
程序代码:
#include <fstream>
#include <string>

using namespace std;

int main()
{
    string line;
    int lineCnt = 0;
    ifstream fin("test.in");
    ofstream fout("test.out");

    while (getline(fin, line))
    {
        ++lineCnt;
    }

    fout << lineCnt << endl;

    return 0;
}

[url=http:///view/aDU1]/image/aDU1.gif" border="0" />[/url]
2011-07-12 12:43
redunkind
Rank: 2
等 级:论坛游民
帖 子:36
专家分:14
注 册:2011-4-10
收藏
得分:0 
回复 5楼 succubus
你是用什么编译的啊??看不懂
2011-07-12 13:17
草狼
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:2
帖 子:577
专家分:1040
注 册:2010-4-6
收藏
得分:0 
回复 4楼 redunkind
当你输入完数据后 按ctrl+z并按回车键就能输出了
2011-07-12 15:19
redunkind
Rank: 2
等 级:论坛游民
帖 子:36
专家分:14
注 册:2011-4-10
收藏
得分:0 
回复 2楼 laoyang103
你看不懂??不会把??

就是输出一共多少行。。。。
2011-07-13 11:55
快速回复:Count the lines of input files
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026090 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved