字符串統計

Problem B:例4003 字符串統計

Time Limit:1000MS  Memory Limit:65536K
Total Submit:371 Accepted:220

Description

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

Input

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

Output

對於每個測試實例,輸出該串中數值的個數,每個輸出佔一行。

Sample Input

2
asdfasdf123123asdfasdf
asdf111111111asdfasdfasdf

Sample Output

6
9



#include <stdio.h>
#include <string.h>
int main(int argc, char const *argv[])
{
	int n,i,j;
	char str[10000];
	while(scanf("%d",&n)!=EOF)
	{
		for (i = 0; i < n; ++i)
		{
			scanf("%s",str);
			//printf("%s\n",str );
			int len=strlen(str);
			int count=0;
			//printf("%d\n",len );
			for(j = 0; j<len ;j++)
			{
			    if(str[j]<=58&&str[j]>=49)
			    {
			       count++;
			    }
			}
			printf("%d\n",count);
		}
	}
	return 0;
}











































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