全篇都是讲数字之间的运算的:

由上自下难度逐渐升级 ,没耐心者建议一拉到底:

1000:

Problem Description
Calculate A + B.
 
Input
Each line will contain two integers A and B. Process to end of file.
 
Output
For each case, output A + B in one line.
 
Sample Input
1 1
 
Sample Output
2

搜到的答案1000.1:

#include <stdio.h>
int main()
{
int a,b;
while(scanf("%d %d",&a,&b)!=EOF)
{
printf("%d\n",a+b);
}
return ;
}

我的代码1000.2:

#include<stdio.h>
#include <stdlib.h>
int main()
{
int a=,b=;
int sum = ;
scanf_s("%d %d", &a,&b);
sum = a + b;
printf("%d", sum);
return ;
}

小结:可以把自己的代码简化 ,如1000.2中的sum求和可以省略直接用printf进行输出。

1089:

Your task is to Calculate a + b.

Input

The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.

Output
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.
 
Sample Input
1 5
10 20
 
Sample Output
6
30
 

搜的代码1089.1:

#include<stdio.h>
int main()
{
int a, b;
while (scanf_s("%d %d", &a, &b) != EOF) // 输入结束时,scanf函数返回值为EOF,即没有数据输入时则退出while循环
printf("%d\n", a + b);
return ; //返回值为0
}

我的代码1089.2:

#include<stdio.h>
#include <stdlib.h>
int main()
{
int a=,b=,c=,d=;
int sum = ,sumo=;
scanf_s("%d %d", &a,&b);
getchar();
scanf_s("%d %d", &c, &d);
sum = a + b;
sumo = c + d;
printf("%d\n%d", sum,sumo);
return ;
}

小结:这里很蠢:我以为题目的意思是连续输入两行,然后连续输出结果,有了代码1089.2.

   但是实际上output: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.的意思是,每输入一行后面就要接一行output,审题不明确。

1090:

Your task is to Calculate a + b.

Input
Input contains an integer N in the first line, and then N lines follow. Each line consists of a pair of integers a and b, separated by a space, one pair of integers per line.
 
Output
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.
 
Sample Input
2
1 5
10 20
 
Sample Output
6 30
 

搜的代码:

 #include<stdio.h>

 int main(void)
{
int a=,b=,N=,i=;
scanf("%d\n",&N);
while(i<N)
{
scanf("%d%d",&a,&b);
printf("%d\n",a+b);
i++;
}
return ;
}

我的代码:

 #include<stdio.h>
int main()
{
int n,a, b;
scanf_s("%d",&n);
while (scanf_s("%d %d", &a, &b) != EOF) // 输入结束时,scanf函数返回值为EOF,即没有数据输入时则退出while循环
printf("%d\n", a + b);
return ; //返回值为0
}

小结:变式多了一个在最开始加一个式子总数的输入,1090.2没有使用到这个总数,而1090.1使用到了这个总数,用while(N--)控制。。

1091:

Problem Description
Your task is to Calculate a + b.
 
Input
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.
 
Output
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.
 
Sample Input
1 5
10 20
0 0
 
Sample Output
6
30
 

搜到的代码1091.1:

 #include<stdio.h>
int main()
{
int a, b;
while (scanf_s("%d%d", &a, &b) == )
{
if (a == && b == ) break;
else printf("%d\n", a + b);
}
return ;
}

我的代码1091.2:

 #include<stdio.h>
int main()
{
int a, b;
int i = ;
while (i != -)
{
scanf_s("%d%d", &a, &b);
if (a == && b == )
return ;
else
printf("%d\n", a + b);
i++; }
}

小结:这个变式我从代码1091.1发现可以通过scanf(***)==n来控制每一组元素的个数,如果scanf设置为n,那么vs会按照输入端输入的值依次选取n个值进行操作(比如:设置n=2,即使键盘输入第一行三个数a1,a2,a3,回车运行,得到的答案依旧是对a1,a2进行操作的结果,接着在输入一行a4,a5,那么结果输出的是对a3,a4操作的结果),有助于进行严格的操作。当然如果不进行设置n值,scanf(****),那么vs会操作每一行相应的元素,不会涉及到上一行。

1092:

Problem Description
Your task is to Calculate the sum of some integers.
 
Input
Input contains multiple test cases. Each test case contains a integer N, and then N integers follow in the same line. A test case starting with 0 terminates the input and this test case is not to be processed.
 
Output
For each group of input integers you should output their sum in one line, and with one line of output for each line in input.
 
Sample Input
4 1 2 3 4
5 1 2 3 4 5
0
 
Sample Output
10
15

搜的代码1092.1:

 #include<stdio.h>
int main()
{
    int n,m,i,sum;
    while(scanf("%d",&n)!=EOF)
    {
        if(n==)
          break;
        sum=;
        for(i=;i<n;i++)
        {
            scanf("%d",&m);
            sum+=m;
        }
        printf("%d\n",sum);
    }
    return ;
 }

以输入0判断结尾

我的代码1092.2:

以输入0判断结尾

小结:我发现循环这一部分用while表达式:“while(n--)”做判断句挺好的,如果n自减到0退出循环,不然就继续循环,相当于:“for(i=n;i>0;i--)”

1093:

Problem Description
Your task is to calculate the sum of some integers.
 
Input
Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.
 
Output
For each group of input integers you should output their sum in one line, and with one line of output for each line in input.
 
Sample Input
2
4 1 2 3 4
5 1 2 3 4 5
 
Sample Output
10
15
 

搜的代码1093.1:

 #include <stdio.h>
#include <stdlib.h>
#define max 100
int main()
{
int x, i, j, n;
scanf_s("%d", &x);
for (j = ; j < x; j++)
{
scanf_s("%d", &n);
int s = , a[max];
for (i = ; i <= n; i++)
scanf_s("%d", &a[i]); for (i = ; i <= n; i++)
s = s + a[i];
printf("%d\n", s);
if (j != x - )printf("\n");
}
return ;
}

我的代码1093.2:

 #include<stdio.h>
int main()
{
int n,m;
int a, sum=;
scanf_s("%d", &m);
while (m--)
{
scanf_s("%d", &n);
{
while (n--)
{
scanf_s("%d", &a);
sum += a;
}
printf("%d", sum);
}
}
return ;
}

小结:1093.1使用的数组做的,嗯可能是vs版本的问题吧(我用的2017) ,搜到的的代码都会有报错,然后加了个#define max 100,然后能正常运行。

1094:

Problem Description
Your task is to calculate the sum of some integers.
 
Input
Input contains multiple test cases, and one case one line. Each case starts with an integer N, and then N integers follow in the same line.
 
Output
For each test case you should output the sum of N integers in one line, and with one line of output for each line in input.
 
Sample Input
4 1 2 3 4
5 1 2 3 4 5
 
Sample Output
10
15

搜的代码:

多行输入,要求按行输出

我的代码:

第一个元素是数字个数

小结:忘记了多行输入的判断方法了:scanf_s("***")!=EOF,然后就扔下了一天。。。说一下EOF:

  "EOF 是end of file的缩写 。

  在用函数读入文件数据的时候,函数总会返回一个状态,是读取成功还是失败,那么这个状态怎么表示呢,所以就约定俗成定义一个标识符表示这个状态,就有了EOF。

  scanf函数只有在第一个参数为NULL(空指针)的情况下,才可能返回EOF,否则,返回成功格式化并赋值的参数个数(>=0)。

  所以,这个循环,将是一个死循环。"

  我太喜欢这个循环了

1095:

Problem Description
Your task is to Calculate a + b.
 
Input
The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.
 
Output
For each pair of input integers a and b you should output the sum of a and b, and followed by a blank line.
 
Sample Input
1 5
10 20
 
Sample Output
6
 
30
 
 
搜的代码:
没搜到(额。。。可能代码太简单了,没有人写)
 

我的代码:

 #include<stdio.h>
int main()
{
int i,a,b,sum=;
while (scanf_s("%d %d", &a,&b) != EOF)
{
printf("%d\n\n",a+b);
}
return ;
}

多行输入,要求按行输出,并带有空行

1096:

Your task is to calculate the sum of some integers.

 
Input
Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.
 
Output
For each group of input integers you should output their sum in one line, and you must note that there is a blank line between outputs.
 
Sample Input
3
4 1 2 3 4
5 1 2 3 4 5
3 1 2 3
 
Sample Output
10
 
15
 
6
 
也没搜到代码,估计这题被觉得没什么创新,所以被抛弃了

我的代码:

#include<stdio.h>
int main()
{
int i,n,m;
scanf_s("%d", &n);
while(n--)
{
scanf_s("%d", &i);
int sum = ;
while (i--)
{
scanf_s("%d",&m);
sum += m;
}
printf("%d\n\n", sum);
}
return ;
}

全篇总结:

不足    :计划上应该是两天练完的,但是我搞了四天,属实是懒

学到了:1.我能灵活的使用循环语句,尤其是while(n--),真好用,推荐;

    2.让文段循环下去的EOF的使用

    3.不至于太生疏的使用数组,写入数据和读出数据

最后,武汉加油!白衣天使们加油!

HDU——算法练习1000 1089-1096的更多相关文章

  1. C++ 的简单输出输入 HDU 1089~1096

    A+B for Input-Output Practice (I) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...

  2. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  3. HDU分类

    原地址:http://www.byywee.com/page/M0/S607/607452.html 总结了一下ACM STEPS的各章内容,趁便附上我的Steps题号(每人的不一样). 别的,此文首 ...

  4. [转] HDU 题目分类

    转载来自:http://www.cppblog.com/acronix/archive/2010/09/24/127536.aspx 分类一: 基础题:1000.1001.1004.1005.1008 ...

  5. hdu 分类

    HDU分类 http://www.cnblogs.com/ACMan/archive/2012/05/26/2519550.html#2667329 努力A完.方便自己系统A题 不断更新中...... ...

  6. 降维算法-PCA主成分分析

    1.PCA算法介绍主成分分析(Principal Components Analysis),简称PCA,是一种数据降维技术,用于数据预处理.一般我们获取的原始数据维度都很高,比如1000个特征,在这1 ...

  7. 杭电acm阶段之理工大版

    想參加全国软件设计大赛C/C++语言组的同学,假设前一篇<C和指针课后练习题总结>没看完的,请先看完而且依照上面的训练做完,然后做以下的训练. 传送门:http://blog.csdn.n ...

  8. 杭州电acm理工大舞台版

    我要参加全国软件设计大赛C/C++学生语言组,前一个假设<C训练和演习,并总结手>没看完,请阅读上述并根据所作的训练,然后做下面的练习. 门户:http://blog.csdn.net/l ...

  9. HD ACM 水题顺序

    原文传送门:http://acm.hdu.edu.cn/ 第一阶段:开始入门吧!(15天,53题) 一.输入输出练习(2天,10题) 1000.1089-1096.1001 二.简单操作:(2-4天, ...

随机推荐

  1. Kubernetes系列三:二进制安装Kubernetes环境

    安装环境: # 三个节点信息 192.168.31.11 主机名:env11 角色:部署Master节点/Node节点/ETCD节点 192.168.31.12 主机名:env12 角色:部署Node ...

  2. vue-router query和params参数的区别

    1.query方式传参和接收参数(相当于get请求) this.$router.push({ path:'/home' query:{ id:1 } }) 接收参数: this.$route.quer ...

  3. 大厂面试题:今天复试百度PHP工程师

    今天下午来到北京百度科技园进行复试PHP工程师岗位. 面试官问了很多问题,我大概整理回忆下: 1.Redis秒杀实现? redis队列解决抢购高并发的原理: 在程序跟数据库之前呢我们可以利用redis ...

  4. python中使用自定义类实例作为字典的key

    python中dict类型的key值要求是不可变类型,通常来说,我们一般采用int或者str类型来作为字典的key,但是在某些场景中,会造成一定的麻烦. 如我们有一个处理http Request的规则 ...

  5. ef codefirst VS里修改数据表结构后更新到数据库

    2.根据已建立table的数据库建立ADO.NET数据模型在修改表后进入 工具->nuget包管理器->程序包管理器控制台 输入  enable-migrations   后vs会添加一个 ...

  6. ExecuteScalar()方法的使用

    ExecuteScalar()方法的作用是: 执行查询,并返回查询所返回的结果集中第一行的第一列.所有其他的列和行将被忽略. 1.返回的是一个object类型,也就是说是所有数据类型的基类,可根据se ...

  7. 乐观锁(Optimistic Lock)

    乐观锁(非阻塞)指不通过锁表来解决并发问题,一般情况下表数据都会加入一个version字段,对该字段进行比较更新来保证数据的一致性. 这里写了个demo,应该可以说明乐观锁的问题. public cl ...

  8. JavaScript学习总结(四)function函数部分

    转自:http://segmentfault.com/a/1190000000660786 概念 函数是由事件驱动的或者当它被调用时执行的可重复使用的代码块. js 支持两种函数:一类是语言内部的函数 ...

  9. Nginx笔记:对url中携带的参数进行多次判断

    Nginx中只支持简单的if语句,不支持多条件判断和嵌套,通过特殊的方式也可以达到效果 location / { proxy_set_header Host $host; proxy_set_head ...

  10. SHELL用法一(基本概念)

    1. SHELL 编程概念入门 1)一个完整 Linux 操作系统(Linux 内核),默认用户是不能直接操作 Linux 内核,需要借助第三方的程序或者软件去操作,例如桌面工具.命令行工具(SHEL ...