sdut-程序设计基础Ⅰ-实验三while循环(1-10)

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;
}
相关推荐
香山上的麻雀10083 分钟前
由 Rust 开发的能大幅降低LLM token消耗的高性能 CLI 代理工具 rtk
开发语言·后端·rust
Fleshy数模3 分钟前
玩转 Python:多线程、装饰器、视觉检测与正则匹配实战
开发语言·python·视觉检测
Felven4 分钟前
B. Make Almost Equal With Mod
数据结构·算法
薛定猫AI4 分钟前
【深度解析】Qwen 3.6 Max Preview:面向智能体编码、视觉推理与 Three.js 前端生成的能力拆解
开发语言·前端·javascript
脆皮炸鸡7555 分钟前
Linux~~基础IO
linux·运维·服务器·经验分享·算法·学习方法
❆VE❆6 分钟前
python实战(一):对接AI大模型并应用
开发语言·人工智能·python·ai
众少成多积小致巨9 分钟前
Android 初始化语言入门
android·linux·c++
colofullove11 分钟前
文本分块策略与预处理
算法
格林威11 分钟前
堡盟Baumer VCX系列工业相机供电与触发:网口(GigE) vs USB3.0
开发语言·人工智能·数码相机·计算机视觉·视觉检测·工业相机·高速相机
yangtuoni11 分钟前
vscode调试C++ python相关配置
c++·vscode·python