`
guanhuaing
  • 浏览: 1199862 次
文章分类
社区版块
存档分类
最新评论

ACM-HDoj暑假竞赛(7)-1010解题报告

 
阅读更多

新浪博客 发表时间 -- 2009-07-27 18:28:54

题目:<wbr></wbr>

<wbr><wbr><wbr><wbr> This problem is strictly to acclimate teams to the contest environment. We strongly suggest you first finish this problem, and then attempt the more complex practice problem.</wbr></wbr></wbr></wbr>

<wbr></wbr>

Input
The input file will contain an unknown number of lines with at most 100 characters on each line. All the characters will be printable ASCII characters. Note that the input file will always exist, but may be empty.
<wbr></wbr>
Output
The number of lines in the input file.
<wbr></wbr>
Sample Input
one and two three
Sample Output
3
算法:
 一看道这题,就知道要设计数器来求它的行数了,一开始设一个数组来接收输入的每一行,然后让计数器count=0,用d=strilen()来求出数组长度,当它到每行末尾时,也就是数组的长度为d时它的值为'\0'就让count++。。。。
代码:
 #include "stdio.h"
#include "string"
int main()
{
<wbr>char str[200];
<wbr>int d,count=0,i;
<wbr>freopen("e:\\z1010.txt","r",stdin);//读文件的
<wbr>while (gets(str))
<wbr>{
<wbr><wbr>d=strlen(str);
<wbr><wbr>for (i=0;i&lt;=d;i++)
<wbr><wbr>{
<wbr><wbr><wbr>if (str[i]=='\0')
<wbr><wbr><wbr>{
<wbr><wbr><wbr><wbr>count++;
<wbr><wbr><wbr>}
<wbr><wbr>}
<wbr>}
<wbr>printf("%d\n",count);
<wbr>return 0;
} </wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics