Your task is to Calculate a + b. Too easy?! Of course! I specially designed the problem for acm beginners. You must have found that some problems have the same titles with this one, yes, all these problems were designed forthe same aim.
Input
1
The input will consist ofa series of pairs of integers aand b, separated byaspace, one pair of integers per line.
Output
1
For each pair of input integers aand b you should output thesumofaand b inoneline, andwithonelineof output foreachlinein input.
Sample Input
1 2
1 5 10 20
Sample Output
1 2
6 30
MyResult
1 2 3 4 5 6 7 8 9 10 11 12
// // Created by Wu Junyi on 2021/9/28. // #include"stdio.h"
intmain(void) { int a, b; while (scanf("%d %d", &a, &b) !=EOF) { printf("%d\n", a+ b); } return0; }
1002
Problem Description
1
Your task is to Calculate a + b.
Input
1
Input containsaninteger N inthefirstline, andthen N lines follow. Each line consists ofa pair of integers aand b, separated byaspace, one pair of integers per line.
Output
1
For each pair of input integers aand b you should output thesumofaand b inoneline, andwithonelineof output foreachlinein input.
Sample Input
1 2 3
2 1 5 10 20
Sample Output
1 2
6 30
MyResult
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// // Created by Wu Junyi on 2021/9/28. //
#include"stdio.h"
intmain(void) { int a, b, n; scanf("%d", &n); while (n--) { scanf("%d %d", &a, &b); printf("%d\n", a + b); } return0; }
1003
Problem Description
1
Your task is to Calculate a + b.
Input
1
Input contains multiple test cases. Each test casecontainsa pair of integers aand b, one pair of integers per line. A test case containing 00 terminates the input and this test case is notto be processed.
Output
1
For each pair of input integers aand b you should output thesumofaand b inoneline, andwithonelineof output foreachlinein input.
Sample Input
1 2 3
1 5 10 20 0 0
Sample Output
1 2
6 30
MyResult
1 2 3 4 5 6 7 8 9 10 11 12 13
// // Created by Wu Junyi on 2021/9/28. //
#include"stdio.h"
intmain(void) { int a, b; while (scanf("%d %d", &a, &b) && (a || b)) { printf("%d\n", a + b); } return0; }
1004
Problem Description
1
Your task isto Calculate the sumofsome integers.
Input
1
Input contains multiple test cases. Each test casecontainsainteger N, andthen N integers follow inthe same line. A test case starting with0 terminates the input and this test case is notto be processed.
Output
1
For each group of input integers you should output their suminoneline, andwithonelineof output foreachlinein input.
Sample Input
1 2 3
4 1234 5 12345 0
Sample Output
1 2
10 15
MyResult
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// // Created by Wu Junyi on 2021/9/28. //
#include"stdio.h"
intmain(void) { int n, a, b; while (scanf("%d", &n) && (n)) { a = 0; while (n--) { scanf("%d", &b); a += b; } printf("%d\n", a); } return0; }
1005
Problem Description
1
Your task isto calculate the sumofsome integers.
Input
1
Input containsaninteger N inthefirstline, andthen N lines follow. Each line starts withainteger M, andthen M integers follow inthe same line.
Output
1
For each group of input integers you should output their suminoneline, andwithonelineof output foreachlinein input.
while (m--) { scanf("%d", &n); a = 0; while (n--) { scanf("%d", &b); a += b; } if (m) printf("%d\n\n", a); elseprintf("%d\n", a); } return0; }
1008
Problem Description
1
Your task isto calculate the sumofsome integers.
Input
1
Input containsaninteger N inthefirstline, andthen N lines follow. Each line starts withainteger M, andthen M integers follow inthe same line.
Output
1
Foreachgroupofinput integers you should output their sum in one line, and you must note that there is a blank linebetween outputs.
Sample Input
1 2 3 4
3 4 1234 5 12345 3 123
Sample Output
1 2 3 4 5
10
15
6
MyResult
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// // Created by Wu Junyi on 2021/9/29. //
#include"stdio.h"
intmain(void) { int n; while (scanf("%d", &n) != EOF) { int sum = 0; for (int i = 1; i <= n; i++) { sum = sum + i; } printf("%d\n\n", sum); } return0; }
1009
Problem Description
1 2
Hey, welcome toHDOJ(Hangzhou Dianzi University Online Judge). In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.
Input
1
The input will consist ofa series of integers n, oneinteger per line.
Output
1
For eachcase, output SUM(n) inoneline, followed bya blank line. You may assume theresult will be inthe range of32-bit signed integer.
intmain(void) { int n, a, b; while (scanf("%d", &n) != EOF) { a = 1; while (n--) { scanf("%d", &b); if (b % 2) { a *= b; } } printf("%d\n", a); } return0; }
WEEK 2
1001
Problem Description
1 2 3 4
Hey, welcome toHDOJ(Hangzhou Dianzi University Online Judge).
In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.
Input
1 2
The input will consist ofa series of integers n, oneinteger per line.
Output
1 2
For eachcase, output SUM(n) inoneline, followed bya blank line. You may assume theresult will be inthe range of32-bit signed integer.
Sample Input
1 2 3
1 100
Sample Output
1 2 3 4 5
1
5050
MyResult
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// // Created by Wu Junyi on 2021/9/30. //
#include"stdio.h"
intmain(void) { long n; while (scanf("%ld", &n) != EOF) { int sum = 0; for (int i = 1; i <= n; i++) { sum = sum + i; } printf("%d\n\n", sum); } return0; }
1002
Problem Description
1 2 3 4
The highest building in our city hasonly one elevator. A request listis made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds tomove the elevator up one floor, and4 seconds tomove down one floor. The elevator will stay for5 seconds at each stop.
For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator ison the 0thfloor at the beginning and does not have toreturnto the ground floor when the requests are fulfilled.
Input
1 2
There are multiple test cases. Eachcase contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100. A test casewith N = 0 denotes the endofinput. This test caseisnotto be processed.
Output
1 2
Print the total timeon a single lineforeach test case.
intmain(void){ int n; while (scanf("%d",&n)&&n){ int i,j,time; j=0; time=n*5; while (n--){ scanf("%d",&i); if (i>j) time+=(i-j)*6; else time+=(j-i)*4; j=i; } printf("%d\n",time); } return0; }
1003
Problem Description
1 2 3
The least common multiple (LCM) ofasetof positive integers is the smallest positive integer which is divisible by all the numbers intheset. For example, the LCM of5, 7and15 is 105.
Input
1 2
Input will consist of multiple problem instances. The firstlineofthe input will contain a single integer indicating thenumberof problem instances. Each instance will consist ofa single lineofthe form m n1 n2 n3 ... nm where m is thenumberof integers inthesetand n1 ... nm are the integers. All integers will be positive and lie withinthe range ofa32-bit integer.
Output
1 2
For each problem instance, output a single line containing the corresponding LCM. All results will lie inthe range ofa32-bit integer.
intgcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); }
intlcm(int a, int b) { return a / gcd(a, b) * b; }
intmain(void) { int n; scanf("%d", &n); while (n--) { int j, k = 1, e; scanf("%d", &j); while (j--) { scanf("%d", &e); k = lcm(k, e); } printf("%d\n", k); } return0; }
1004
Problem Description
1 2 3 4 5 6
A number sequence is defined as follows:
f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.
Given A, B, and n, you are to calculate the value of f(n).
Input
1
The input consists of multiple test cases. Each test case contains 3 integers A, B and n on a single line (1 <= A, B <= 1000, 1 <= n <= 100,000,000). Three zeros signal the endofinputand this test caseisnotto be processed.
Output
1 2
For each test case, print the value of f(n) on a single line.
intmain(void) { int A, B, n; // for (int i = 3 ; i <100 ; ++i) { // f[i] = (f[i-1] + f[i-2])%7; // printf("%d: %d\n",i,f[i]); // }
while (scanf("%d%d%d", &A, &B, &n) && (A || B || n)) { int f[50] = {0, 1, 1}; for (int i = 3; i < 50; ++i) { f[i] = (A * f[i - 1] + B * f[i - 2]) % 7; }
intmain(void) { int i, j, a = 0, t; scanf("%d", &i); while (i--) { __int64 n = 0; scanf("%d", &j); while (j--) { scanf("%d", &t); n += t; if (t > a)a = t; } if (a - (n - a) <= 1)printf("Yes\n"); elseprintf("No\n"); a = 0; } return0; }
intmain() { int a, b; while (scanf("%d %d", &a, &b) && (a || b)) { int i, s = a; for (i = 0; i < b - 1; i++) s = s * a % 1000; printf("%d\n", s); } return0; }
1008
Problem Description
1 2
Given a positive integer N, you should output the most right digit of N^N.
Input
1 2 3
The input contains several test cases. The firstlineofthe input is a single integer T which is thenumberof test cases. T test cases follow. Each test casecontainsa single positive integer N(1<=N<=1,000,000,000).
Output
1 2
For each test case, you should output the rightmost digit of N^N.
Sample Input
1 2 3 4
2 3 4
Sample Output
1 2 3 4 5 6 7
7 6
# Hint In the first case, 3 * 3 * 3 = 27, so the rightmost digit is 7. In the second case, 4 * 4 * 4 * 4 = 256, so the rightmost digit is 6. </div>
intmy_power(int m, int n); // 求m的n次方的尾数 intmain(void) { int cases, n; scanf("%d", &cases); while (cases--) { scanf("%d", &n); printf("%d\n", my_power(n, n)); }
return0; }
intmy_power(int m, int n) { m = m % 10; if (n == 1) return m; if (n % 2 == 0) return (my_power(m * m, n / 2)) % 10; else return (my_power(m * m, n / 2) * m) % 10; }