序列求和???我不会【哭】
序列求和
https://ac.nowcoder.com/acm/problem/14387
第二次不明白为什么数组要开这么大,10个我觉得都多,为啥不能用gets()函数呢???
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main(){
char str[1000000];
scanf("%s", str);
int len = strlen(str);
int sum = 0;
for(int i = 0; i < len; i++){
int temp = str[i]-'0';
sum += temp;
}
printf("%d", sum);
return 0;
}case通过率为40.00%,应该是超时了
#include<cstdio>
int main(){
int n;
scanf("%d", &n);
int sum = 0;
while(n != 0){
int temp = n % 10;
sum += temp;
n /= 10;
}
printf("%d", sum);
return 0;
}
查看6道真题和解析

