codeup之A+B 输入输出练习I 、II 、III、IV、V、VI、VII、VIII(黑盒测试
不建议做,掌握书上几种情况即可,题简单又重复
I Description
你的任务是计算a+b。这是为了acm初学者专门设计的题目。你肯定发现还有其他题目跟这道题的标题类似,这些问题也都是专门为初学者提供的。
Input
输入包含一系列的a和b对,通过空格隔开。一对a和b占一行。
Output
对于输入的每对a和b,你需要依次输出a、b的和。
如对于输入中的第二对a和b,在输出中它们的和应该也在第二行。
Sample Input Copy
1 5
10 20
Sample Output Copy
6
30
solution
#include <stdio.h>
int main(){
int a, b;
while(scanf("%d %d", &a, &b) != EOF)
printf("%d\n", a + b);
return 0;
}
II Description
你的任务是计算a+b。
Input
第一行是一个整数N,表示后面会有N行a和b,通过空格隔开。
Output
对于输入的每对a和b,你需要在相应的行输出a、b的和。
如第二对a和b,对应的和也输出在第二行。
Sample Input Copy
2
1 5
10 20
Sample Output Copy
6
30
solution
#include <stdio.h>
int main(){
int a, b, n;
scanf("%d", &n);
while(n--){
scanf("%d %d", &a, &b);
printf("%d\n", a + b);
}
return 0;
}
III Description
你的任务是计算a+b。
Input
输入中每行是一对a和b。其中会有一对是0和0标志着输入结束,且这一对不要计算。
Output
对于输入的每对a和b,你需要在相应的行输出a、b的和。
如第二对a和b,他们的和也输出在第二行。
Sample Input Copy
1 5
10 20
0 0
Sample Output Copy
6
30
solution
#include <stdio.h>
int main(){
int a, b;
while(scanf("%d %d", &a, &b), a || b){
printf("%d\n", a + b);
}
return 0;
}
IV Description
你的任务是计算若干整数的和。
Input
每行的第一个数N,表示本行后面有N个数。
如果N=0时,表示输入结束,且这一行不要计算。
Output
对于每一行数据需要在相应的行输出和。
Sample Input Copy
4 1 2 3 4
5 1 2 3 4 5
0
Sample Output Copy
10
15
solution
#include <stdio.h>
int main(){
int n, sum, x;
while(scanf("%d", &n), n){
sum = 0;
for(int i = 0; i < n; i++){
scanf("%d", &x);
sum += x;
}
printf("%d\n", sum);
}
return 0;
}
V Description
你的任务是计算若干整数的和。
Input
输入的第一行是一个正数N,表示后面有N行。每一行的第一个数是M,表示本行后面还有M个数。
Output
对于每一行数据需要在相应的行输出和。
Sample Input Copy
2
4 1 2 3 4
5 1 2 3 4 5
Sample Output Copy
10
15
solution
#include <stdio.h>
int main(){
int n, m, sum, x;
scanf("%d", &n);
while(n--){
scanf("%d", &m);
sum = 0;
for(int i = 0; i < m; i++){
scanf("%d", &x);
sum += x;
}
printf("%d\n", sum);
}
return 0;
}
VI Description
你的任务是计算若干整数的和。
Input
每行的第一个数N,表示本行后面有N个数。
Output
对于每一行数据需要在相应的行输出和。
Sample Input Copy
4 1 2 3 4
5 1 2 3 4 5
Sample Output Copy
10
15
solution
#include <stdio.h>
int main(){
int n, sum, x;
while(scanf("%d", &n) != EOF){
sum = 0;
for(int i = 0; i < n; i++){
scanf("%d", &x);
sum += x;
}
printf("%d\n", sum);
}
return 0;
}
VII Description
你的任务是计算两个整数的和。
Input
输入包含若干行,每行输入两个整数a和b,由空格分隔。
Output
对于每组输入,输出a和b的和,每行输出后接一个空行。
Sample Input Copy
1 5
10 20
Sample Output Copy
6
30
solution
#include <stdio.h>
int main(){
int a, b;
while(scanf("%d %d", &a, &b) != EOF){
printf("%d\n\n", a + b);
}
return 0;
}
VIII Description
你的任务是计算若干整数的和。
Input
输入的第一行为一个整数N,接下来N行每行先输入一个整数M,然后在同一行内输入M个整数。
Output
对于每组输入,输出M个数的和,每组输出之间输出一个空行。
Sample Input Copy
3
4 1 2 3 4
5 1 2 3 4 5
3 1 2 3
Sample Output Copy
10
15
6
solution
#include <stdio.h>
int main(){
int n, m, sum, x;
scanf("%d", &n);
while(n--){
scanf("%d", &m);
sum = 0;
for(int i = 0; i < m; i++){
scanf("%d", &x);
sum += x;
}
printf("%d\n\n", sum);
}
return 0;
}
codeup之A+B 输入输出练习I 、II 、III、IV、V、VI、VII、VIII(黑盒测试的更多相关文章
- 买卖股票的最佳时机I II III IV
I 假设有一个数组,它的第i个元素是一支给定的股票在第i天的价格.如果你最多只允许完成一次交易(例如,一次买卖股票),设计一个算法来找出最大利润. II 假设有一个数组,它的第i个元素是一个给定的股票 ...
- hdu 3081 hdu 3277 hdu 3416 Marriage Match II III IV //灵活运用最大流量
3081 意甲冠军: n女生选择不吵架,他甚至男孩边(他的朋友也算.并为您收集过程).2二分图,一些副作用,有几个追求完美搭配(每场比赛没有重复的每一个点的比赛) 后.每次增广一单位,(一次完美匹配) ...
- LeetCode之“动态规划”:Best Time to Buy and Sell Stock I && II && III && IV
Best Time to Buy and Sell Stock I 题目链接 题目要求: Say you have an array for which the ith element is the ...
- combination sum(I, II, III, IV)
II 简单dfs vector<vector<int>> combinationSum2(vector<int>& candidates, int targ ...
- Two Sum I & II & III & IV
Two Sum I Given an array of integers, find two numbers such that they add up to a specific target nu ...
- hdu 3081 hdu 3277 hdu 3416 Marriage Match II III IV //最大流的灵活运用
3081 题意: n个女孩选择没有与自己吵过架的男孩有连边(自己的朋友也算,并查集处理),2分图,有些边,求有几种完美匹配(每次匹配每个点都不重复匹配) 我是建二分图后,每次增广一单位,(一次完美匹配 ...
- Best Time to Buy and Sell Stock I II III IV
一.Best Time to Buy and Sell Stock I Say you have an array for which the ith element is the price of ...
- Leetcode 137. Single Number I/II/III
Given an array of integers, every element appears twice except for one. Find that single one. 本题利用XO ...
- LeetCode Single Number I / II / III
[1]LeetCode 136 Single Number 题意:奇数个数,其中除了一个数只出现一次外,其他数都是成对出现,比如1,2,2,3,3...,求出该单个数. 解法:容易想到异或的性质,两个 ...
- 1. Two Sum I & II & III
1. Given an array of integers, return indices of the two numbers such that they add up to a specific ...
随机推荐
- Linux - 配置IP&主机名的快捷操作
nmtui 执行以下命令可以进入一个可视化界面,进行IP的可视化配置.以及网络服务的重启(注意,这个重启是停止然后启动, 如果使用xshell进行操作会失去ssh连接,直连服务器时可这直接操作).主机 ...
- 再谈Mysql undo log, redo log与binlog
一.undo log 1.undo log有两个作用 提供回滚和多个行版本控制(MVCC). 在数据修改的时候,不仅记录了redo log,还记录了对应的undo,如果因为某些原因事务失败而回滚,可以 ...
- python文件不显示cmd黑窗口,打包py,pyw文件为exe文件
问题描述:编写的python文件为定时任务,需要长时间运行,但是打开的cmd黑色窗口看起来很不舒服,于是打包为exe文件,隐藏cmd黑色窗口 步骤:1.使用pip install pyinstalle ...
- (附体验地址)大模型知识引擎:AI 助手能否助力销售技能提升?
体验地址:https://lke.cloud.tencent.com/webim_exp/#/chat/FAIMcM 腾讯云的大模型知识引擎本身定位于为企业客户及合作伙伴提供服务,因此我在探索如何最佳 ...
- U盘制作、安装Ubuntu系统
制作 ubuntu U盘启动盘 下载Ubuntu镜像 打开 Ubuntu 官网:https://ubuntu.com/download/desktop ,进入页面后,点击右边的[Download]按钮 ...
- $GOPATH/go.mod exists but should not
开启模块支持后,并不能与GOPATH共存,所以把项目从GOPATH中移出即可
- Oracle临时表会随另外一个表的创建自动提交并清空
创建一个临时表,用它导入一些数据 用这个临时表生成另外一个表,用create table ... 但生成的这表总是空的. 原来create table 前会进行提交commit, 而临时表在commi ...
- (踩坑)windows本地部署Dify ,玩转智能体、知识库
windows 安装docker windows 本地部署deepseek windows 通过docker本地部署dify 一:安装Docker 前提: 开启Hyper-V 打开 控制面 ...
- Goland搭建Go开发环境
1.下载和安装Golang 下载链接: 谷歌链接:https://golang.google.cn/dl/ 国内链接:https://studygolang.com/dl 安装示意图: 安装完成后配置 ...
- 为什么 Java 中 CMS 垃圾收集器在发生 Concurrent Mode Failure 时的 Full GC 是单线程的?
为什么 Java 中 CMS 垃圾收集器在发生 Concurrent Mode Failure 时的 Full GC 是单线程的? 在 CMS(Concurrent Mark-Sweep)垃圾收集器中 ...