Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/32768 K (Java/Others)
[顯示标簽]
Description
對于給定的一個字元串,統計其中數字字元出現的次數。
Input
輸入資料有多行,第一行是一個整數n,表示測試執行個體的個數,後面跟着n行,每行包括一個由字母和數字組成的字元串。
Output
對于每個測試執行個體,輸出該串中數值的個數,每個輸出占一行。
Sample Input
2
asdfasdf123123asdfasdf
asdf111111111asdfasdfasdf
Sample Output
6
9
Hint
lcy
Source
C語言程式設計練習(三)
Related problem
2015 2013 2012 2010 2016
周遊一下再做判斷就好了啊.這裡用的了string,跟字元串差不多,不過其長度用size()得出。
代碼如下:
#include <iostream>
#include <string.h>
using namespace std;
int main ()
{
int n;
cin>>n;
while(n--)
{
string a;
int count=0;
cin>>a;
for(int i=0;i<a.size();i++)
{
if(a[i]<='9'&&a[i]>='0')
count++;
}
cout<<count<<endl;
}
}