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

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

 

题目: 

     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.

 

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.
 
Output
The number of lines in the input file.
 
Sample Input
one and two three
Sample Output
3
算法:
 一看道这题,就知道要设计数器来求它的行数了,一开始设一个数组来接收输入的每一行,然后让计数器count=0,用d=strilen()来求出数组长度,当它到每行末尾时,也就是数组的长度为d时它的值为'\0'就让count++。。。。
代码:
 #include "stdio.h"
#include "string"
int main()
{
 char str[200];
 int d,count=0,i;
 freopen("e:\\z1010.txt","r",stdin);//读文件的
 while (gets(str))
 {
  d=strlen(str);
  for (i=0;i<=d;i++)
  {
   if (str[i]=='\0')
   {
    count++;
   }
  }
 }
 printf("%d\n",count);
 return 0;
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值