3418. 数字字符个数

三七茧茧

数据较大,考虑用getchar()将字符一个一个接受判断

include

include

include

include

include

int main()
{
char c;
int cnt=0;
c=getchar();
if(c>=48&&c<=57)
cnt++;
while(c!=’\n’&&c!=’\r’)
{

    c=getchar();
    if(c>=48&&c<=57)
        cnt++;
}
printf("%d\n",cnt);

}

Fifnmar

水水更健康

#include <cctype>
#include <iostream>
#include <string>

using namespace std;
int main() {
    ios::sync_with_stdio(false);
    string a;
    getline(cin, a);
    unsigned cnt = 0;
    for (auto const &i : a) {
        if (isdigit(i))
            ++cnt;
    }
    cout << cnt;
}
ALICE

include

include

int main(){
char c;
int n=0;
while((c=getchar())!=’\n’){
if(c>=‘0’&&c<=‘9’)n=n+1;
else n=n;
}
printf(“%d\n”,n);

}

1574080260

在60M以下,用数组的同学注意别申请在践上

include

char st[11858764] = {‘\0’};
int main(){
gets(st);
int i, x=0;
for(i=0; i<11858764; i++){
if(st[i] == ‘\0’){
break;
}
else {
x += (st[i] <= 57 && st[i] >= 48);
}
}
printf(“%d”,x);
}

zuozug

…runtime

Canis

python水题很爽,另外这个题用java又会超时QAQ
str = input()
cnt = 0
for i in str:
if i.isdigit():
cnt += 1
print(cnt)

sst12345

include

include

using namespace std;
int main(){
string a;
cin>>a;
int count=0;
int b=a.length();
for(int i=0;i=48&&a[i]<=57)
count++;
}
cout<<count<<endl;
}

sst12345

为什么错误呀

13627999316

用getline处理,可能有空格,你这样输入中间就断了

你当前正在回复 博客/题目
存在问题!