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;
}
相关推荐
带鱼吃猫18 小时前
C++ 智能指针全解析:从 RAII 到自定义删除器的内存管理艺术
开发语言·c++
R6bandito_18 小时前
自实现FLASH读取函数中的隐式类型转换bug踩坑记录
c语言·开发语言·经验分享·stm32·单片机·mcu·bug
memcpy018 小时前
LeetCode 1208. 尽可能使字符串相等【不定长滑窗,字符串】1497
算法·leetcode·职场和发展
阿Y加油吧18 小时前
LeetCode 二叉树双王炸!二叉树展开为链表 + 前序 + 中序还原二叉树|小白递归一把过
算法·leetcode·链表
AI科技星18 小时前
全球AI信息场(信息网)基础理论与数学建模研究(乖乖数学)
开发语言·人工智能·线性代数·算法·机器学习·数学建模
汉克老师18 小时前
GESP2024年12月认证C++三级( 第一部分选择题(9-15))
c++·字符串·位运算·进制·补码·gesp三级·gesp3级
云中飞鸿18 小时前
qt中显示日志的一般是哪个控件?
开发语言·qt
仟濹18 小时前
【算法打卡day37(2026-04-04 周六)】DFS专项训练4-枚举专项训练 1-全部是蓝桥杯真题
算法·蓝桥杯·深度优先
汀、人工智能18 小时前
12 - 内置函数:Python的瑞士军刀
数据结构·算法·数据库架构·图论·python的瑞士军刀
梦游钓鱼18 小时前
虚继承实现原理详解及案例
c++