1089-1096
2015-07-27 08:55
447 查看
杭电的几道a+b,控制格式的题,大概整理一下....
1089
数据会超过int,用long long 型。
1090
事先给定需要测试的组数,用循环来判断是否终止
1091
考察的特殊终止的格式,需要在循环条件处加限定
1092
输入一个数n,后边是n个数,求和,n是0的时候程序终止
输入一个数字,代表一共几组测试
每组第一个数字 n ,代表计算n个数的和,后边是 n 个数。
1094
读取到文件结束(相当于无限组输入),每组第一个数代表需要计算几个数的和。
1095
计算a+b,每组之后一个空行
1096
输入一个数,代表有多少组测试数据,每组第一个数代表本组有几个数字,输出这几个数字的和
每两组数据之间有空行,最后一组数据后没有空行。
1089-1096,这几个题,考查的是基本的输入和输出格式,基本上把所有的竞赛格式包括完了,格式掌握了,剩下的就是学习解决问题的方法了.....
加油!!
1089
数据会超过int,用long long 型。
/* Sample Input 1 5 10 20 Sample Output 6 30 */ #include<stdio.h> int main() { long long a,b; while(~scanf("%lld%lld",&a,&b)) { printf("%lld\n"a+b); } return 0; }
1090
事先给定需要测试的组数,用循环来判断是否终止
/* Sample Input 2 1 5 10 20 Sample Output 6 30 */ #include<stdio.h> int main() { long long a,b; int t; scanf("%d",&t); while(t--) { scanf("%lld%lld",&a,&b); printf("%lld\n",a+b); } return 0; }
1091
考察的特殊终止的格式,需要在循环条件处加限定
/* Sample Input 1 5 10 20 0 0 Sample Output 6 30 */ #include<stdio.h> int main() { long long a,b; while(scanf("%lld%lld",&a,&b),(a||b)) { printf("%lld\n",a+b); } return 0; }
1092
输入一个数n,后边是n个数,求和,n是0的时候程序终止
/* Sample Input 4 1 2 3 4 5 1 2 3 4 5 0 Sample Output 10 15 */ #include<stdio.h> int main() { int i,n;long long a,s; while(scanf("%d",&n),n) { s=0; for(i=0;i<n;i++) { scanf("%lld",&a); s+=a; } printf("%lld\n",s); } return 0; }1093
输入一个数字,代表一共几组测试
每组第一个数字 n ,代表计算n个数的和,后边是 n 个数。
/* Sample Input 2 4 1 2 3 4 5 1 2 3 4 5 Sample Output 10 15 */ #include<stdio.h> int main() { long long a,s;int i,n,t; scanf("%d",&t); while(t--) { scanf("%d",&n); s=0; for(i=0;i<n;i++) { scanf("%lld",&a); s+=a; } printf("%lld\n",s); } return 0; }
1094
读取到文件结束(相当于无限组输入),每组第一个数代表需要计算几个数的和。
/* Sample Input 4 1 2 3 4 5 1 2 3 4 5 Sample Output 10 15 */ #include<stdio.h> int main() { long long a,s;int i,n; while(~scanf("%d",&n)) { s=0; for(i=0;i<n;i++) { scanf("%lld",&a); s+=a; } printf("%lld\n",s); } return 0; }
1095
计算a+b,每组之后一个空行
/* Sample Input 1 5 10 20 Sample Output 6 30 */ #include<stdio.h> int main() { long long a,b; while(~scanf("%lld%lld",&a,&b)) { printf("%lld\n\n",a+b); } return 0; }
1096
输入一个数,代表有多少组测试数据,每组第一个数代表本组有几个数字,输出这几个数字的和
每两组数据之间有空行,最后一组数据后没有空行。
/* 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 n,i,m,a,b,sum; scanf("%d",&n); for(i=0;i<n;i++) { sum=0; scanf("%d",&m); while(m--) { scanf("%d",&a); sum+=a; } printf("%d\n",sum); if(i<n-1) { printf("\n"); } } return 0; }
1089-1096,这几个题,考查的是基本的输入和输出格式,基本上把所有的竞赛格式包括完了,格式掌握了,剩下的就是学习解决问题的方法了.....
加油!!
相关文章推荐
- Linux帮助命令
- 数学_LightOJ_1008
- .net单元测试框架xUnit.net
- Android root漏洞分析汇总
- 设计模式学习笔记十一:观察者模式
- js在方法Ajax请求数据来推断,验证无效(OnClientClick="return Method();"),或者直接运行的代码隐藏
- 修改配置文件之前一定要备份
- QWidget属性,函数的学习
- 设计模式学习笔记十一:观察者模式
- Linux Out-Of-Memory(OOM) Killer分析
- Linux Out-Of-Memory(OOM) Killer分析
- 白皮书是什么意思?
- 请教大家,如何使用sed命令,替换文件指定行的内容呢?-Linux系统管理-ChinaUnix.net
- 网上删除所有数据文件的恢复情况
- 猜数字(规律)
- Linux vim 常用命令
- The return type is incompatible with JspSourceDependent.getDependants():JasperException问题分析与解决方法
- The return type is incompatible with JspSourceDependent.getDependants():JasperException问题分析与解决方法...
- Spring IOC源码详解之容器依赖注入
- 学习Html和css的神级工具sublim