18 条题解
- 1
信息
- ID
- 387
- 时间
- 1000ms
- 内存
- 16MiB
- 难度
- 3
- 标签
- 递交数
- 514
- 已通过
- 288
- 上传者
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, sum = 0;
cin >> n;
while (n > 0)
{
sum += n % 10;
n /= 10;
}
cout << sum;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,a,b,c,d;
cin>>n;
a=n%10; //个位
b=n/10%10; //十位
c=n/100%10; //百位
d=n/1000; //千位
cout<<a+b+c+d; //和
return 0;
}
又是贱贱担担的一道题辣👀️ 上代码🚀️
#include <bits/stdc++.h>
using namespace std;
int s;
int main()
{
string n;
cin >> n;
for (int i = 0; i < 4 ; i++) s += n[i] - '0';//直接遍历字符串再累加
cout << s;
return 0;
}
已AC,观众老爷勿喷👀️
`
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
int a = n / 1000;
int b = n / 100 % 10;
int c = n / 10 % 10;
int d = n % 10;
cout << a + b + c + d;
return 0;
}
过辣!
string s;
long long sum=0;
cin>>s;
for (int i=0;i<s.length();++i)
{
sum+=(s[i]-'0');
}
cout<<sum;
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,sum=0;
cin>>n;
while(n)
{
sum+=n%10;
n/=10;
}
cout<<sum;
}//简单 已AC
你这只能在DevC++上运行,return都没有
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define s string
ll sum;
s n;
int main(){
cin>>n;
cout<<(n[0]-'0')+(n[1]-'0')+(n[2]-'0')+(n[3]-'0');
return 0;
}
#include <iostream>
using namespace std;
int main(){
int x,sum=0;
cin>>x;
while(x)sum+=x%10,x/=10;
cout<<sum<<endl;
return 0;
}
//已AC,勿喷❤️ ;
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,g,s,b,q;
cin >> n;
q = n / 1000;
b = n / 100 % 10;
s = n / 10 % 10;
g = n % 10;
cout << q + b + s + g;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
cout << n % 10 + n % 100 / 10 + n % 1000 / 100 + n / 1000;
}
a = input()
ans = 0
for i in a:
ans += int(i)
print(ans)
少了return 0;
你指的谁???
?
#include<bits/stdc++.h> using namespace std; int main(){ int n,s=0,a,b,c,d; cin>>n; a=n/1000; b=n/100-a10; c=n/10-a100-b10; d=n-a1000-b100-c10; s=a+b+c+d; cout<<s; return 0; }
#include <bits/stdc++.h>
using namespace std;
int main()
{
cout << 3;
return 0;
}
这么写得33分