7-1 sdut-C语言实验-A+B for Input-Output Practice (不确定次数循环)
Your task is to Calculate a + b.
Too easy?! Of course! I specially designed the problem for all beginners.
You must have found that some problems have the same titles with this one, yes, all these problems were designed for the same aim.
输入格式:
The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.
输出格式:
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.
输入样例:
1 5
10 20
输出样例:
在这里给出相应的输出。例如:
6
30
实现代码:
cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
int m,n;
while(cin>>m>>n){
cout<<m+n<<endl;
}
return 0;
}
7-2 sdut-C语言实验-偶数数位求和
给定一个整数,请求出这个整数所有数位中是偶数的数位的和。例如,对于12436546,那么答案就是 2 + 4 + 6 + 4 + 6 。
输入格式:
输入一个数 n 。 (0 <= n <= 2147483647)
输出格式:
输出 n 的所有偶数数位的和。
输入样例:
6768
输出样例:
在这里给出相应的输出。例如:
20
实现代码:
cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
int m,n,sum=0;
cin>>m;
while(m>0){
n=m%10;
if(n%2==0)
sum=sum+n;
m=m/10;
}
cout<<sum;
return 0;
}
7-3 sdut-C语言实验-小树快长高
小明在植树节种了一棵小树。小明每天都给小树浇水,盼望着小树快快长高。他知道小树现在有 n cm,每天长高k cm,他想知道多少天小树可以长到m cm。
输入格式:
输入三个整数 n, m, k。 ( 0 <= n<= 10000, 0 <= m <= 10000,0 <= k <= 10000)
输出格式:
输出一个整数,即需要的天数。
输入样例:
在这里给出一组输入。例如:
100 200 5
输出样例:
在这里给出相应的输出。例如:
20
实现代码:
cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
int m,n,k;
cin>>n>>m>>k;
if(m==n) cout<<0;
else if((m-n)%k==0) cout<<(m-n)/k;
else cout<<(m-n)/k+1;
return 0;
}
7-4 sdut-C语言实验-数位数
给定一个正整数 n ,请你求出它的位数。
输入格式:
单组输入,输入一个整数 n 。(1<= n <= 2147483647)
输出格式:
输出一行,包含一个整数,即为 n 的位数。
输入样例:
1234567
输出样例:
在这里给出相应的输出。例如:
7
实现代码:
cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
int m,n,sum=0;
cin>>m;
while(m>0){
sum=sum+1;
m=m/10;
}
cout<<sum;
return 0;
}
7-5 sdut-C语言实验- 数列求和2
正整数序列是指从1开始的序列,例如{1,2,3,4,......}
给定一个整数 n,现在请你求出正整数序列 1 - n 的和。
输入格式:
输入一个整数 n 。(1 <= n <= 1000)
输出格式:
输出一个整数,即为正确答案。
输入样例:
2
输出样例:
在这里给出相应的输出。例如:
3
实现代码:
cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
int m,n=1,sum=0;
cin>>m;
while(n<=m){
sum=sum+n;
n++;
}
cout<<sum;
return 0;
}
7-6 sdut-C语言实验-N^3问题
输入一个正整数N,求出N^3的各位数字的立方和。
输入格式:
输入N的值。N<=1024
输出格式:
问题描述中所要求的数值。
输入样例:
3
输出样例:
在这里给出相应的输出。例如:
351
实现代码:
cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
int m,n,k,sum=0;
cin>>m;
n=m*m*m;
while(n>0){
k=n%10;
sum=sum+k*k*k;
n=n/10;
}
cout<<sum;
return 0;
}
7-7 sdut-C语言实验-虎子的难题
虎子是个爱学习的孩子,暑假也在家有规律的学习,但是他最近碰到了一道难题,题目是这样的:
给出一个正整数 n 和数字 m ( m 取值范围[0,9]中的一个数字),求 m 在 n 中出现的次数。
比如 n = 2122345 , m = 2,答案就是 3 ,因为 2 在 2122345 中出现了三次。
你能帮帮他吗?
输入格式:
输入只有一行,包含两个空格分开的整数 n 和 m 。(0 <= m <= 9,1 <= n <= 2147483647)
输出格式:
输出一个数字,表示 m 在 n 中 出现的次数。
输入样例:
在这里给出一组输入。例如:
2122345 2
输出样例:
在这里给出相应的输出。例如:
3
实现代码:
cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
int m,n,sum=0;
scanf("%d %d",&n,&m);
while(n>0){
if (m==n%10){
sum=sum+1;
}
n=n/10;
}
cout<<sum;
return 0;
}
7-8 sdut-C语言实验- A+B for Input-Output Practice (I)
Your task is to Calculate a + b.
Too easy?! Of course! I specially designed the problem for acm beginners.
You must have found that some problems have the same titles with this one, yes, all these problems were designed for the same aim
输入格式:
The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.
输出格式:
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.
输入样例:
1 5
10 20
输出样例:
在这里给出相应的输出。例如:
6
30
实现代码:
cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
int m,n;
while(cin>>m>>n){
cout<<m+n<<endl;
}
return 0;
}
7-9 sdut-C语言实验- A+B for Input-Output Practice (II)
Your task is to Calculate a + b.
输入格式:
Input contains multiple test cases. Each test case contains a pair of integers a and b, one pair of integers per line. A test case containing 0 0 terminates the input and this test case is not to be processed.
输出格式:
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.
输入样例:
1 5
10 20
0 0
输出样例:
6
30
实现代码:
cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
int m,n;
while(scanf("%d %d\n",&m,&n)!=EOF){
if(m==0&&n==0)
break;
cout<<m+n<<endl;
}
return 0;
}
7-10 sdut-C语言实验-A+B for Input-Output Practice (III)
Your task is to Calculate a + b.
输入格式:
The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.
输出格式:
For each pair of input integers a and b you should output the sum of a and b, and followed by a blank line.
输入样例:
在这里给出一组输入。例如:
1 5
10 20
输出样例:
在这里给出相应的输出。例如:
6
30
代码长度限制
实现代码:
cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
int m,n;
while(scanf("%d %d\n",&m,&n)!=EOF){
cout<<m+n<<endl;
cout<<endl;
}
return 0;
}