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;
}
相关推荐
写代码写到手抽筋5 小时前
5G上行DCI字段判定:端口 流数 PMI选择详解
java·算法·5g
xieliyu.5 小时前
Java算法精讲:双指针(二)
java·开发语言·算法
苏宸啊5 小时前
IPC管道
linux·c++
何以解忧,唯有..6 小时前
Python包管理工具pip:从入门到精通
开发语言·python·pip
BestOrNothing_20156 小时前
ROS2 话题通信实战:消息对象、Publisher 发布器与 Subscriber 订阅器保姆级教程
c++·ros2·subscriber·publisher·话题通信
wayz116 小时前
Momentum:PSL(心理线指标)技术指标详解
算法·金融·数据分析·量化交易·特征工程
雪的季节6 小时前
RabbitMQ详解
开发语言
8Qi87 小时前
LeetCode 213:打家劫舍 II(House Robber II)—— 题解 ✅
算法·leetcode·职场和发展·动态规划
ice8130331817 小时前
【Python】Matplotlib折线图绘制
开发语言·python·matplotlib
三品吉他手会点灯7 小时前
C语言学习笔记 - 44.运算符和表达式 - 运算符2 - 除法与取余运算符
c语言·开发语言·笔记·算法