【算法学习】-常见输入输出方式
程序员文章站
2022-06-09 08:42:21
...
hdu-1089
AC代码:
//hdu-1089【A+B for Input-Output Practice (I) 】
#include<stdio.h>
int main(){
int a,b;
while(~scanf("%d%d",&a,&b)){
printf("%d\n",a+b);
}
return 0;
}
hdu-1090
AC代码:
//hdu-1090【A+B for Input-Output Practice (II)】
#include<stdio.h>
int main(){
int n,a,b;
scanf("%d",&n);
while(n--){
scanf("%d%d",&a,&b);
printf("%d\n",a+b);
}
return 0;
}
hdu-1091
AC代码:
//A+B for Input-Output Practice (III)
#include<stdio.h>
int main(){
int a,b;
while(scanf("%d%d",&a,&b)&&(a||b)){
printf("%d\n",a+b);
}
return 0;
}
hdu-1092
AC代码:
//A+B for Input-Output Practice (IV)
#include<stdio.h>
int main(){
int n,a;
while(scanf("%d",&n)&&n){
int sum=0;
while(n--){
scanf("%d",&a);
sum+=a;
}
printf("%d\n",sum);
}
return 0;
}
hdu-1093
AC代码:
//A+B for Input-Output Practice (V)
#include<stdio.h>
int main(){
int t,n,a;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
int s=0;
while(n--){
scanf("%d",&a);
s+=a;
}
printf("%d\n",s);
}
return 0;
}
hdu-1094
AC代码:
//A+B for Input-Output Practice (VI)
#include<stdio.h>
int main(){
int n,a;
while(~scanf("%d",&n)){
int s=0;
while(n--){
scanf("%d",&a);
s+=a;
}
printf("%d\n",s);
}
return 0;
}
hdu-1095
AC代码:
//A+B for Input-Output Practice (VII)
#include<stdio.h>
int main(){
int a,b;
while(scanf("%d%d",&a,&b)!=EOF){
printf("%d\n\n",a+b);
}
return 0;
}
hdu-1096
AC代码:
//A+B for Input-Output Practice (VIII)
#include<stdio.h>
int main(){
int t,n,a;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
int s=0;
while(n--){
scanf("%d",&a);
s+=a;
}
(t!=0)?printf("%d\n\n",s):printf("%d\n",s);
}
return 0;
}