Day1 hdoj 1089-1096 problem, day11089-1096
First step into ACM learning, I have to strongly recommend a set of videos
Https://space.bilibili.com/3071253!
The video of the up Master is very similar to me.
I have never learned c ++, but I still don't know much about the c language array.
First, the basic input/output format is 1089-1096.
The following code is provided. Search for the original question by yourself.
1089
#include<stdio.h>int main(){ int a,b; while(scanf("%d%d",&a,&b)!=EOF) printf("%d\n",a+b); return 0;}
This is the most basic a + B problem
The only clever thing is
while(scanf("%d%d",&a,&b)!=EOF)
EOF is end of file
In general, the meaning of this Code is
You can always enter a and B values without stopping.
If it is normal
scanf("%d%d",&a,&b);
After a value of a + B is calculated, the program terminates.
1090
#include<stdio.h>int main(){ int a,b,n; scanf("%d",&n); while(n>0) { n--; scanf("%d%d",&a,&b); printf("%d\n",a+b); } return 0;}
In particular, you can enter a number n to control the number of groups that can be entered.
The feature code here is
while(n>0) { n--; }
Please follow the video to understand
1091
#include<stdio.h>int main(){ int a,b; while(scanf("%d%d",&a,&b)!=EOF) { if(a==0&&b==0) break; printf("%d\n",a+b); } return 0;}
This topic is special
If the input is 0, the program is terminated.
In the code, break indicates that the while LOOP jumps out and returns 0; that is, the program is terminated.
1092
# Include <stdio. h> int main () {int a, n; while (scanf ("% d", & n )! = EOF) {if (n = 0) break; int sum = 0; // pay special attention to the position where sum is assigned 0 while (n> 0) {n --; scanf ("% d", & a); sum + = a;} printf ("% d \ n", sum);} return 0 ;}
This topic is special
Specifies the number of numbers entered in each group.
Same principle as question 1090
1093
#include<stdio.h>int main(){ int a,n,i; scanf("%d",&i); while(i>0) { i--; scanf("%d",&n); { if(n==0) break; int sum=0; while(n>0) {n--; scanf("%d",&a); sum+=a; } printf("%d\n",sum); } } return 0;}
1090 and 1092
Specify the number of groups and the number of numbers in each group
Use twice while.
1094
#include<stdio.h>int main(){ int a,n; while(scanf("%d",&n)!=EOF) { int sum=0; while(n--){ scanf("%d",&a); sum+=a; } printf("%d\n",sum); } return 0;}
Water
Only the AC code is provided.
1095
#include<stdio.h>int main(){ int a,b; while(scanf("%d%d",&a,&b)!=EOF) printf("%d\n\n",a+b); return 0;}
Output by line
Similarly, only the AC code is provided.
1096
#include<stdio.h>int main(){ int n,i,a; scanf("%d",&n); while(n--) { scanf("%d",&i); int sum=0; while(i--) { scanf("%d",&a); sum+=a; } if(n>0) printf("%d\n\n",sum); else printf("%d\n",sum); } return 0;}
Overall
Note that PE appears when printf ("% d \ n", sum) is directly typed for the first time.
The format may end with \ n.
If you are not sure, we recommend that you use 1096 output code.