HDU:2017 字符串統計

#
Problem Description

對於給定的一個字符串,統計其中數字字符出現的次數。
 

Input
輸入數據有多行,第一行是一個整數n,表示測試實例的個數,後面跟着n行,每行包括一個由字母和數字組成的字符串。
 

Output
對於每個測試實例,輸出該串中數值的個數,每個輸出佔一行。
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <string.h>

int main()
{
    int n,i,j;
    char v;
    scanf("%d",&n);
    getchar();
    for(i=0;i<n;i++){
        j=0;
        while((v=getchar())!='\n'){
            if(v>='0'&&v<='9')j++;
        }
        printf("%d\n",j);
    }
    return 0;
}

 

Sample Input
2 asdfasdf123123asdfasdf asdf111111111asdfasdfasdf
 

Sample Output
6 9

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