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;
}
相关推荐
ZhengEnCi10 分钟前
同样的模型,为什么本地和云 API 差别那么大:量化精度、聊天模板与采样参数的三大元凶
人工智能·算法·llm
Wang's Blog21 分钟前
Java 项目实战:交友项目 - 用户体系集成总结
java·开发语言·交友
会编程的小孩28 分钟前
C++ 定时器
c++
Flynn Liang30 分钟前
RAG 答非所问/幻觉怎么破?Spring AI QuestionAnswerAdvisor 召回优化实战(TopK/重排/混合检索)
人工智能·算法·spring·rag·幻觉·springai
liminla!1 小时前
SQL 从入门到进阶:语法速查与实战练习(完整优化版)
数据库·sql·算法
中科三方1 小时前
IPv6检测常见问题:AAAA记录检测不通过是什么原因?
开发语言·php
沫璃染墨2 小时前
从零入门计算机网络系列(十一):HTTP协议进阶——从重定向原理到GET/POST与Fiddler抓包
linux·服务器·开发语言·网络·c++·tcp/ip·html
维克兜率天2 小时前
【维克】指数调整:哪些股票会被“强制买入“?
人工智能·python·算法
刚入门的大一新生2 小时前
Linux-线程互斥
java·开发语言
香芋芋圆2 小时前
iD-editor 详解|OSM官方在线编辑器,基于D3.js的轻量地图编辑器
开发语言·javascript·编辑器