目录
Ⅰ.基本运算
前两个练习不想写了,实在是太简单了没话说(主要是没时间写,以后有空再补上)
3.拆位练习
1605: 【入门】求一个两位数的个位和十位的和
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,g=0,s=0;
cin>>n;
g=n%10;
s=n/10;
cout<<g+s;
return 0;
}
1606: 【入门】求一个两位数倒序的结果
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,g=0,s=0;
cin>>n;
g=n%10;
s=n/10;
if(g==0){
cout<<s;
}else{
cout<<g<<s;
}
return 0;
}
1027: 【入门】求任意三位数各个数位上数字的和
#include<bits/stdc++.h>
using namespace std;
int main(){
int x,g,s,b=0;
cin>>x;
g=x%10;
s=x/10%10;
b=x/100;
cout<<g+s+b;
return 0;
}
1028: 【入门】输入一个三位数,把个位和百位对调后输出
本人题解(较繁琐,可参考下方较优题解):
#include<bits/stdc++.h>
using namespace std;
int main(){
int x,g,s,b=0;
cin>>x;
g=x%10;
s=x/10%10;
b=x/100;
if(g==0&&s==0){
cout<<b;
}else if(g==0){
cout<<s<<b;
}else{
cout<<g<<s<<b;
}
return 0;
}
较优题解(转载于东方博宜程序题解_sphile-CSDN博客):
#include <iostream>
using namespace std;
int main(){
int n;
cin>>n;
cout<<n%10*100+n/100+n%100/10*10;
return 0;
}
1390: 【入门】四位数的和
#include<bits/stdc++.h>
using namespace std;
int main(){
int x,t,sum=0;
cin>>x;
t=x;
while(t>0){
sum+=t%10;
t/=10;
}
cout<<sum;
return 0;
}
1607: 【入门】两位数运算
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
double sum=0,g=0,s=0;
cin