hdu 2017 字符串統計

#include <stdio.h>
#include <string.h>
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int i,len,t=0;
        char ch[1000];
        scanf("%s",ch);
        len = strlen(ch);
        for(i=0;i<len;i++)
        {
            if(ch[i]>='0'&&ch[i]<='9')
            t++;
        }
        printf("%d\n",t);
    }
    return 0;
}//AC
下面這個是更大範圍的,不僅僅是1000的

#include<stdio.h>
#include<string.h>
int main()
{
    int n;
    scanf("%d",&n);
    getchar();
    while(n--)
    {
              int t=0;
      //getchar();
      char ch;
      while(scanf("%c",&ch),ch!='\n')
      {
        if(ch>='0'&&ch<='9')
        t++;
      }
      printf("%d\n",t);
    }
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章