题解
2024-11-23 09:51:18
发布于:浙江
13阅读
0回复
0点赞
#include<iostream>
#include<cstring>
using namespace std;
int main(){
char a[110];
fgets(a,110,stdin);
int n=strlen(a),c=0;
for(int i=0;i<n;i++){
if(a[i]=='1'){
c++;
}else if(a[i]=='2'){
c+=2;
}else if(a[i]=='3'){
c+=3;
}else if(a[i]=='4'){
c+=4;
}else if(a[i]=='5'){
c+=5;
}else if(a[i]=='6'){
c+=6;
}else if(a[i]=='7'){
c+=7;
}else if(a[i]=='8'){
c+=8;
}else if(a[i]=='9'){
c+=9;
}
}
if(c==0){
cout<<'0';
}else{
cout<<c;
}
return 0;
}
#include<iostream>
#include<cstring>
using namespace std;
int main(){
char c[110];
fgets(c,110,stdin);
int sum=0;
for(int i=0;i<strlen(c);i++){
if(c[i]>='0'&&c[i]<='9'){
sum+=c[i]-'0';
}
}
cout<<sum;
return 0;
}
#include<iostream>
#include<string>
using namespace std;
int main(){
string c;
getline(cin,c);
int sum=0;
for(int i=0;i<c.size();i++){
if(c[i]>='0'&&c[i]<='9'){
sum+=c[i]-'0';
}
}
cout<<sum;
return 0;
}
这里空空如也
有帮助,赞一个