统计并输出每个字符串中阿拉伯数字的个数

| December 4, 2007 20:06 | timmy | Via Original
连续输入一批以 # 结束的字符串(字符串的长度不超过80),遇 ## 则全部输入结束。
统计并输出每个字符串中阿拉伯数字的个数。
例:括号内是说明
输入:
S0df345gr63#=ahbg##   (连续输入2个字符串)
输出:
6     ("S0df345gr63"中有6个阿拉伯数字)
0    ("ahbg"中没有阿拉伯数字)


#include "stdio.h"
#define MAXLEN 80
int main( )
{  int count,i,k;
   char ch,oldch,str[MAXLEN];
   oldch=' ';
   while((ch=getchar())!='#'||oldch!='#'){
      k=0;
      while(ch!='#'&& k< MAXLEN-1){
       str[k++]=ch;
       ch=getchar();
      }
      oldch='#';
      str[k]='\0';
    count=0;
    for(i=0;i<k;i++)
      if(str[i]>='0'&&str[i]<='9')
        count++;
      printf("%d\n",count);
   }
}
Tags:
Program/Code » C/C++ | Comments(0) | Trackbacks(0) | Reads(225)
Add a comment
 Site URI
 Email
  Password Optional
 Nickname  *  [Register]
               

 
Emots
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
Enable HTML
Enable UBB
Enable Emots
Hidden
Remember