HDOJ10 day question sequence

Four or five roads a day (1.1 represents the first road on the first day), from easy to difficult

Let's share my results. They are all AC. please give me your opinion~

### Article directory

- 1.1.HDOJ 1000
- 1.2.HDOJ 1089
- 1.3.HDOJ1096
- 1.4.HDOJ1001
- 1.5.HDOJ 2000
- 2.1 HDOJ 2001
- 2.2 HDOJ 2002
- 2.3 absolute value of hdoj2003
- 2.4 HDOJ 2004 Grade conversion
- 2.5HDOJ2005
- 3.1 HDOJ 2010
- 3.2 HDOJ 2039
- 3.3 HDOJ1720 conversion base
- 3.4HDOJ 1062 flip character
- 3.5 hdoj 2104 (mutual quality)
- 4.1HDOJ 1064 average
- 4.2HDOJ 2734
- 4.3 hdoj 1170 calculator
- 4.4HDOJ 1197 conversion
- 5.1HDOJ 2629 identity card correspondence
- 5.2HDOJ 2012 prime number determination
- 5.3HDOJ2013 eating flat peach (review)
- 5.4 hdoj 2014 (average)
- 5.5hdoj 2015 even sum
- 5.6 2016
- 6.1HDOJ2017 string number
- 6.2HDOJ 2018 cow story
- 6.3HDOJ2019 inserting numbers
- 6.4HDOJ 2020 absolute value ranking
- 7.1 HDOJ 2021 salary
- 7.2 HDOJ2022 audition female host
- 7.3HDOJ2023 average score
- 7.4HDOJ2024 judge legal identifier
- 8.1 finding the largest element in hdoj 2025
- 8.2HDOJ2027 digital vowel
- 8.3HDOJ2026 capitalize initial
- 8.4HDOJ2028 calculate the minimum common multiple of n numbers.
- 8.5HDOJ 2029 palindromes
- 9.1 HDOJ 2030 Chinese character statistics
- 9.2 HDOJ 2032 Yanghui triangle
- 9.3 HDOJ 2040 affinity number
- 9.4HDOJ 2042 difficult Series II
- 9.5 HDOJ 2055 AN EASY PROBLEM
- 10.1HDOJ1050 mobile table (greedy algorithm)
- 10.2HDOJ1051 stick problem (greedy algorithm)
- 10.3HDOJ1051 stick problem (greedy algorithm)

## 1.1.HDOJ 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

#include <iostream> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { int a; int b; while(cin>>a>>b){ //each line cout<<a+b<<endl; //PE in case of endl loss } return 0; }

## 1.2.HDOJ 1089

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

#include <iostream> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { int a,b; while(cin>>a>>b){ cout<<a+b<<endl; } return 0; }

## 1.3.HDOJ1096

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 <iostream> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { int N,M,num; cin>>N; int sum=0; while(N--){ cin>>M; sum=0; while (M--){ cin>>num; sum+=num; } if(N!=0){ cout<<sum<<endl; //Note that there should be blank lines between each output line cout<<endl; } else { cout<<sum<<endl; //The output of the last line does not need to enter again } } return 0; }

## 1.4.HDOJ1001

Input

The input will consist of a series of integers n, one integer per line.

Output

For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.

Sample Input

1 100

Sample Output

1 5050

#include <iostream> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { int num,sum; while(cin>>num){ sum=num; while(num--){ sum+=num; } cout<<sum<<endl<<endl; } return 0; }

## 1.5.HDOJ 2000

Problem Description

After three characters are input, the three characters are output in the order of the ASCII code of each character from small to large.

Input

There are multiple groups of input data, each group occupies a row, which is composed of three characters, and there is no space between them.

Output

For each group of input data, output a line, separated by a space between the characters.

Sample Input

qwe asd zxc

Sample Output

e q w a d s c x z

Answer 1 (correct and necessary)

#include <iostream> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv){ char a,b,c,temp; while(cin>>a>>b>>c){ //Here, we have realized the following groups of data that are not implemented in the two-dimensional array if(a>b){ temp=a; a=b; b=temp; } if(a>c){ temp=a; a=c; c=temp; } if(b>c){ temp=b; b=c; c=temp; } cout<<a<<" "<<b<<" "<<c<<endl; } return 0; }

wrong, because they don't say it's a two-dimensional array of three times three

#include <iostream> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv){ char c[3][3]; char in,temp; int i=0,j=0; while(i <3){ j=0; while(j<3){ cin>>in ; c[i][j++]=in; } ++i; } //bubble sort int k=0; while(k<3){ for(int m = 3;m>=1;m--) { for(int n = 1;n<m;n++){ if(c[k][n]<c[k][n-1]){ temp=c[k][n]; c[k][n]=c[k][n-1]; c[k][n-1]=temp; } } } ++k; } //put out for(int a =0;a<3;a++){ for(int b=0;b<3;b++){ cout<<c[a][b]<<" "; } cout<<endl; } return 0; }

## 2.1 HDOJ 2001

Problem Description

Input the coordinates of two points (X1,Y1), (X2,Y2), calculate and output the distance between two points.

Input

There are multiple groups of input data, each group occupies a row, which is composed of four real numbers, representing x1,y1,x2,y2 respectively. The data is separated by spaces.

Output

For each group of input data, output one row, and keep two decimal places for the result.

Sample Input

0 0 0 1 0 1 1 0

Sample Output

1.00 1.41

#include <iostream> #include <iomanip>//Keep small tree header file #include <math.h>//Root number using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { float x1,x2,y1,y2,s,d; while(cin>>x1>>y1>>x2>>y2){ s=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2); s=sqrt(s); cout<<setiosflags(ios::fixed)<<setprecision(2)<<s<<endl;//Keep two decimal places // Cout < < fixed < < setprecision (2) < s < < endl; / / fixed is OK, submitted } return 0; }

## 2.2 HDOJ 2002

Problem Description

Calculates the volume of the ball based on the entered radius value.

Input

There are multiple groups of input data, each group occupies a row, each row includes a real number, which represents the radius of the ball.

Output

Output the volume of the corresponding ball. For each group of input data, output a row, and keep three decimal places for the calculation result.

Sample Input

1 1.5

Sample Output

4.189 14.137 Hint #define PI 3.1415927

#include <iostream> #include <math.h> #include <iomanip> #define PI 3.1415927 using namespace std; int main(int argc, char** argv) { double r,v; //The first time float was wrong answer, the development type was not enough while(cin>>r){ v=4*PI*r*r*r/3; cout<<fixed<<setprecision(3)<<v<<endl; } return 0; }

## 2.3 absolute value of hdoj2003

Problem Description

Find the absolute value of the real number.

Input

There are multiple groups of input data, each group occupies a row, and each row contains a real number.

Output

For each group of input data, output its absolute value. Each group of data is required to output one row, with two decimal places reserved for the result.

Sample Input

123 -234.00

Sample Output

123.00 234.00

#include <iostream> #include <math.h> #include <iomanip> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { double a; while(cin>>a){ if(a<0){ a=0-a; } cout<<fixed<<setprecision(2)<<a<<endl; } return 0; }

## 2.4 HDOJ 2004 Grade conversion

Problem Description

Enter the score t of a centesimal system and convert it to the corresponding grade. The specific conversion rules are as follows:

90~100 is A;

80~89 is B;

70~79 is C;

60~69 is D;

0~59 is E;

Input

There are multiple groups of input data, each group occupies a row, and each group consists of an integer.

Output

For each set of input data, output one row. If the input data is not in the range of 0-100, please output a line: "Score is error!".

Sample Input

56 67 100 123

Sample Output

E D A Score is error!

#include <iostream> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { int t; while(cin>>t){ if(t>=90&&t<=100){ cout<<"A"<<endl; } else if(t>=80&&t<=89){ cout<<"B"<<endl; } else if(t>=70&&t<=79){ cout<<"C"<<endl; } else if(t>=60&&t<=69){ cout<<"D"<<endl; } else if(t>=0&&t<=59){ cout<<"E"<<endl; } else { cout<<"Score is error!"<<endl; } } return 0; }

## 2.5HDOJ2005

Problem Description

Given a date, the output date is the day of the year.

Input

There are multiple groups of input data, each group occupies a row, and the data format is YYYY/MM/DD. for details, see sample input. In addition, you can be assured that all input data is legal.

Output

For each group of input data, output a row, indicating that the date is the day of the year.

Sample Input

1985/1/20 2006/3/12

Sample Output

20 71

#include <iostream> using namespace std; //judge leap year int leap(int y){ //Judge leap year by mistake or by mistake and lead to wrong answer if((y%4==0&&y%100!=0)||y%400==0){ return 1; } return 0; } int main(int argc, char** argv) { int y,m,d,flag,sum; char month[12]={31,28,31,30,31,30,31,31,30,31,30,31}; while(scanf("%d/%d/%d",&y,&m,&d)!=EOF){ sum=0; flag=leap(y); if(m>2){ sum+=flag; } for(int i=0;i<m-1;i++){ sum+=month[i]; } sum+=d; cout<<sum<<endl; } return 0; }

## 3.1 HDOJ 2010

Problem Description

Spring is the season of flowers, among which Narcissus is the most charming representative. There is a number of Narcissus in mathematics, which is defined as follows:

"Narcissus number" refers to a three digit number whose cubic sum of each digit is equal to itself, for example: 153 = 13 + 53 + 3 ^ 3.

Now you need to output all the Narcissus numbers in the m and n ranges.

Input

There are multiple groups of input data, each group occupies a row, including two integers m and n (100 < = m < = n < = 999).

Output

For each test instance, it is required to output all the number of daffodils in a given range, that is, the number of daffodils output must be greater than or equal to m, and less than or equal to n. if there are more than one, it is required to arrange the output in a row from small to large, separated by a space;

If the number of Narcissus does not exist in the given range, no is output;

The output of each test instance takes up one line.

Sample Input

100 120 300 380

Sample Output

no 370 371

#include <iostream> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ //Judge Narcissus int flower(int m){ int x,y,z; x=m%10; y=m/10%10; z=m/100%10; if(m==x*x*x+y*y*y+z*z*z){ return 1; } return 0; } int main(int argc, char** argv) { int m,n,num,i,flag,sum=0; int f[9000]; while(cin>>m>>n){ num = m; sum = 0; while(num<=n){ if(flower(num)){ //It's Narcissus f[sum++]=num; num++; } else{ num++; } } i=0; flag=0; if(sum>0){ while(i<sum){ //Need flag help to separate with space if(flag==1){ //Separated by a space is the last number without a space, pit: cout < < f [i + +] < ""; cout<<" "; } cout<<f[i++]; flag=1; } cout<<endl; } else{ cout<<"no"<<endl; } } return 0; }

## 3.2 HDOJ 2039

Problem Description

Given three sides, please judge if you can make a triangle.

Input

The first row of input data contains a number m, followed by M rows, each row has an instance, including three positive numbers A,B,C. A,B,C < 1000;

Output

For each test case, if three sides a, B and C can form a triangle, output YES, otherwise NO.

Sample Input

2 1 2 3 2 2 2

Sample Output

NO YES

#include <iostream> #include <math.h> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { double m,a,b,c; //Say it's a positive number (double), not a positive integer (int) cin>>m; //Positive number positive integer while(m--){ cin>>a>>b>>c; if(a+b>c&&a+c>b&&b+c>a){ cout<<"YES"<<endl; } else if(a>999||b>999||c>999||a<0||b<0||c<0){ //Can be omitted, submitted for verification return 0; } else{ cout<<"NO"<<endl; } } return 0; }

## 3.3 HDOJ1720 conversion base

Problem Description

Many classmates said to me that A+B is must needs.

If you can't AC this problem, you would invite me for night meal. _

Input

Input may contain multiple test cases. Each case contains A and B in one line.

A, B are hexadecimal number.

Input terminates by EOF.

Output

Output A+B in decimal number in one line.

Sample Input

1 9 A B a b

Sample Output

10 21 21

#include <iostream> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { int a,b; cin>>hex; while (cin>>a>>b){ a+=b; cout<<dec; cout<<a<<endl; } return 0; }

## 3.4HDOJ 1062 flip character

Problem Description

Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them.

Input

The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.

Each test case contains a single line with several words. There will be at most 1000 characters in a line.

Output

For each test case, you should output the text which is processed.

Sample Input

3 olleh !dlrow m'I morf .udh I ekil .mca

Sample Output

hello world! I'm from hdu. I like acm. Hint Remember to use getchar() to read '\n' after the interger T, then you may use gets() to read a line and process it.

#include <iostream> #include <string.h> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { int t,j,flag=-1; char str[1000]; char s1[1000]; cin>>t; getchar(); //Receive the new line, you will enter the new line after t while(t--){ gets(str); int len=strlen(str); //Pay attention to the function of finding the array,. length() is not recognized. Remember the header file. h. note that strlen is used for arrays flag = -1; for(int i=0;i<=len;i++){ if(str[i]==' ' || i==len) { //No need to create a new array to store words for(j=i-1;j>=0&&j!=flag;j--){//In case of blank space, mark with flag, and stop output here next time cout<<str[j]; } flag=i; if(i!=len){ cout<<" "; } } } cout<<endl; } return 0; }

## 3.5 hdoj 2104 (mutual quality)

Problem Description

The Children's Day has passed for some days .Has you remembered something happened at your childhood? I remembered I often played a game called hide handkerchief with my friends.

Now I introduce the game to you. Suppose there are N people played the game ,who sit on the ground forming a circle ,everyone owns a box behind them .Also there is a beautiful handkerchief hid in a box which is one of the boxes .

Then Haha(a friend of mine) is called to find the handkerchief. But he has a strange habit. Each time he will search the next box which is separated by M-1 boxes from the current box. For example, there are three boxes named A,B,C, and now Haha is at place of A. now he decide the M if equal to 2, so he will search A first, then he will search the C box, for C is separated by 2-1 = 1 box B from the current box A . Then he will search the box B ,then he will search the box A.

So after three times he establishes that he can find the beautiful handkerchief. Now I will give you N and M, can you tell me that Haha is able to find the handkerchief or not. If he can, you should tell me "YES", else tell me "POOR Haha".

Input

There will be several test cases; each case input contains two integers N and M, which satisfy the relationship: 1<=M<=100000000 and 3<=N<=100000000. When N=-1 and M=-1 means the end of input case, and you should not process the data.

Output

For each input case, you should only the result that Haha can find the handkerchief or not.

Sample Input

3 2 -1 -1

Sample Output

YES

**Answer 1 (correct and necessary, can you see that mutual quality is required)**

#include <iostream> #include <math.h> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ //Reciprocal Prime: division by rolling //When the remainder is 0, the divisor of the current formula is taken as the maximum common divisor, so the maximum common divisor 1 of 1997 and 615 is obtained. //If n and m are not mutually prime, it will appear that some people will never find it. The greatest common factor of mutual prime is 1, that is to say, the number between other doors with interval of 1 will traverse int check(int n,int m){ while(m){ int r=n%m; n=m; m=r; } return n; } int main(int argc, char** argv){ int n,m; while(cin>>n>>m){ if(n==-1&&m==-1){ return 0; } int r=check(n,m); if(r==1){ cout<<"YES"<<endl; } else{ cout<<"POOR Haha"<<endl; } } return 0; }

**Answer 2 (wrong, unable to overcome array definition and 3 array out of bounds)**

#include <iostream> #include <math.h> using namespace std; int main(int argc, char** argv) { int m,n=100,r=1,count; //r means to find box at this time while(cin>>n>>m){ long int flag[n]={0};//If the compilation fails, it can't overcome how to determine the length of the array. If you directly define 100 million, the memory will exceed the limit flag[r] =1; if(n==-1&&m==-1){ return 0; } else{ count = 0; while(count<n){ r=r+m; if(r>n){ r=r%n; } flag[r]=1; count++; //Count's looking for a few people } } for(int i=1;i<=n;i++){ //i start with 1, because children count from 1 if(flag[i]==0){ cout<<"POOR Haha"<<endl; break; } if(i==n){ //No 0 at the end of traversal cout<<"YES"<<endl; } } } return 0; }

## 4.1HDOJ 1064 average

Problem Description

Larry graduated this year and finally has a job. He's making a lot of money, but somehow never seems to have enough. Larry has decided that he needs to grab hold of his financial portfolio and solve his financing problems. The first step is to figure out what's been going on with his money. Larry has his bank account statements and wants to see how much money he has. Help Larry by writing a program to take his closing balance from each of the past twelve months and calculate his average account balance.

Input

The input will be twelve lines. Each line will contain the closing balance of his bank account for a particular month. Each number will be positive and displayed to the penny. No dollar sign will be included.

Output

The output will be a single number, the average (mean) of the closing balances for the twelve months. It will be rounded to the nearest penny, preceded immediately by a dollar sign, and followed by the end-of-line. There will be no other spaces or characters in the output.

Sample Input

100.00 489.12 12454.12 1234.10 823.05 109.20 5.27 1542.25 839.18 83.99 1295.01 1.75

Sample Output

$1581.42

#include <iostream> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { double ave=0,n=0,sum=0; int m=0; while(m<12){ cin>>n; m++; sum+=n; } ave=sum/12; cout<<"$"<<ave<<endl; return 0; }

## 4.2HDOJ 2734

ACM: 11 + 23 + 313 = 46MID CENTRAL: 113 + 29 + 34 + 40 + 53 + 65 + 714 + 820 + 918 + 101 + 1112 = 650

Input

The input consists of one or more packets followed by a line containing only # that signals the end of the input. Each packet is on a line by itself, does not begin or end with a space, and contains from 1 to 255 characters.

Output

For each packet, output its Quicksum on a separate line in the output.

Sample Input

ACM MID CENTRAL REGIONAL PROGRAMMING CONTEST ACN A C M ABC BBC #

Sample Output

46 650 4690 49 75 14 15

#include <iostream> #include <string.h> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { char c; char str[1000]; int count,num; while(gets(str)){ if(str[0] =='#'){ //Here is the array, write str = = "Chen", no return 1; } int len=strlen(str); //strlen is for arrays, not strings int i = 0 ; int sum=0; while(i!=len){ while(str[i]==' '){ i++; } num=str[i]-'A'+1; num*=(i+1); sum+=num; i++; } cout<<sum<<endl; } return 0; }

## 4.3 hdoj 1170 calculator

Problem Description

The contest starts now! How excited it is to see balloons floating around. You, one of the best programmers in HDU, can get a very beautiful balloon if only you have solved the very very very... easy problem.

Give you an operator (+,-,*, / --denoting addition, subtraction, multiplication, division respectively) and two positive integers, your task is to output the result.

Is it very easy?

Come on, guy! PLMM will send you a beautiful Balloon right now!

Good Luck!

Input

Input contains multiple test cases. The first line of the input is a single integer T (0<T<1000) which is the number of test cases. T test cases follow. Each test case contains a char C (+,-,*, /) and two integers A and B(0<A,B<10000).Of course, we all know that A and B are operands and C is an operator.

Output

For each case, print the operation result. The result should be rounded to 2 decimal places If and only if it is not an integer.

Sample Input

4 + 1 2 - 1 2 * 1 2 / 1 2

#include <iostream> #include <math.h> #include <iomanip> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ double op(char c,int a,int b){ double r; if(c=='+') { r=a+b; } else if(c=='-') { r=a-b; } else if(c=='*') { r=a*b; } else if(c=='/') { if(b!=0){ r=(double)a/b; } //Division is an integer by default, and two decimal places should be reserved for conversion to float } return r; } int main(int argc, char** argv) { int t,a,b; char c; double r; cin>>t; while(t--){ cin>>c>>a>>b; r=op(c,a,b); if(c=='/'&&a%b!=0) { cout<<fixed<<setprecision(2)<<r<<endl;//Division takes decimal into account } else{ cout<<(int)r<<endl; //If we don't convert r here, we will still have double type } } return 0; }

## 4.4HDOJ 1197 conversion

Problem Description

Find and list all four-digit numbers in decimal notation that have the property that the sum of its four digits equals the sum of its digits when represented in hexadecimal (base 16) notation and also equals the sum of its digits when represented in duodecimal (base 12) notation.

For example, the number 2991 has the sum of (decimal) digits 2+9+9+1 = 21. Since 2991 = 11728 + 8144 + 9*12 + 3, its duodecimal representation is 1893(12), and these digits also sum up to 21. But in hexadecimal 2991 is BAF16, and 11+10+15 = 36, so 2991 should be rejected by your program.

The next number (2992), however, has digits that sum to 22 in all three representations (including BB016), so 2992 should be on the listed output. (We don't want decimal numbers with fewer than four digits - excluding leading zeroes - so that 2992 is the first correct answer.)

Input

There is no input for this problem.

Output

Your output is to be 2992 and all larger four-digit numbers that satisfy the requirements (in strictly increasing order), each on a separate line with no leading or trailing blanks, ending with a new-line character. There are to be no blank lines in the output. The first few lines of the output are shown below.

Sample Input

There is no input for this problem.

Sample Output

2992 2993 2994 2995 2996 2997 2998 2999

#include <iostream> #include <math.h> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { int a,b,c,d,e,s1,s2,s3; for(a=1000;a<10000;a++){ b=a%10; c=a/10%10; d=a/100%10; e=a/1000%10; s1=b+c+d+e; b=a%12; //Notice that the dodecal number conversion method has been tossed several times c=a/12%12; d=a/12/12%12; e=a/12/12/12%12; s2=b+c+d+e; b=a%16; c=a/16%16; d=a/16/16%16; e=a/16/16/16%16; s3=b+c+d+e; if(s1==s2 &&s2==s3){ cout<<a<<endl; } } return 0; }

## 5.1HDOJ 2629 identity card correspondence

Problem Description

Do you own an ID card?You must have a identity card number in your family's Household Register. From the ID card you can get specific personal information of everyone. The number has 18 bits,the first 17 bits contain special specially meanings:the first 6 bits represent the region you come from,then comes the next 8 bits which stand for your birthday.What do other 4 bits represent?You can Baidu or Google it.

Here is the codes which represent the region you are in.

However,in your card,maybe only 33 appears,0000 is replaced by other numbers.

Here is Samuel's ID number 331004198910120036 can you tell where he is from?The first 2 numbers tell that he is from Zhengjiang Province,number 19891012 is his birthday date (yy/mm/dd).

Input

Input will contain 2 parts:

A number n in the first line,n here means there is n test cases. For each of the test cases,there is a string of the ID card number.

Output

Based on the table output where he is from and when is his birthday. The format you can refer to the Sample Output.

Sample Input

1 330000198910120036

Sample Output

He/She is from Zhejiang,and his/her birthday is on 10,12,1989 based on the table.

#include <iostream> #include<string.h> #include <math.h> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { char id[18]; int n,p; cin>>n; getchar(); //When receiving the back carriage return, I almost mistakenly think that it is while(n --) that leads to less acceptance of a group while(n--){ gets(id); p=(id[0]-'0')*10+(id[1]-'0'); cout<<"He/She is from "; if(p==33){ cout<<"Zhejiang,"; } if(p==11){ cout<<"Beijing,"; } if(p==71){ cout<<"Taiwan,"; } if(p==81){ cout<<"Hong Kong,"; } if(p==82){ cout<<"Macao,"; } if(p==54){ cout<<"Tibet,"; } if(p==21){ cout<<"Liaoning,"; } if(p==31){ cout<<"Shanghai,"; } cout<<"and his/her birthday is on "; cout<<id[10]<<id[11]<<","<<id[12]<<id[13] <<','<<id[6]<<id[7]<<id[8]<<id[9]; cout<<" based on the table."<<endl; } return 0; }

## 5.2HDOJ 2012 prime number determination

Problem Description

For the expression n^2+n+41, when n takes an integer value (including x,y) in the range of (x,y) (- 39 < = x < y < = 50), it is determined whether all the values of the expression are prime numbers.

Input

There are multiple groups of input data, each group occupies a row, which is composed of two integers x, Y. when x=0,y=0, it means the input is finished, and the row will not be processed.

Output

For each value within a given range, if the value of the expression is a prime number, the output is "OK", otherwise, please output "Sorry", with each group of output occupying one line.

Sample Input

0 1 0 0

Sample Output

OK

#include <iostream> #include <math.h> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int prime(int i){//Four conditions, one less wrong if(i==1){ return 0; } else if(i==2){ //Pay attention to the first three prime number determination conditions return 1; } else if( i<=0){ return 0; } else { for (int j=2;j<i;j++){ //Note that j starts from 2, j < I is not<= if(i%j==0){ return 0; } } return 1; } } int main(int argc, char** argv) { int a,b,c,flag=0; while(cin>>a>>b){ flag=0; if(a<-39||b>50) break; else{ if(a==0&&b==0){ break; } for(int i=a;i<=b;i++){ c=i*i+i+41; if(prime(c)==1) { flag=1; continue; } else if(!prime(c)){ flag=0; break; } } if(flag==1){ cout<<"OK"<<endl; } else if(flag==0){ cout<<"Sorry"<<endl; } } } return 0; }

## 5.3HDOJ2013 eating flat peach (review)

Problem Description

All the students who like the journey to the West must know the story of monkey eating flat peaches. You must think the monkey is too noisy. In fact, you don't know: monkey is studying a mathematical problem!

What's the problem? The question he studied was how many peaches there were!

However, in the end, he still failed to solve the problem, ha ha-

It was like this:

On the first day, Wukong ate more than one and a half peaches in total. On the second day, he ate more than one and a half of the rest peaches. Later, he ate more than one and a half of the rest of the day before each day, and only one peach was left when he was ready to eat on the nth day. Smart you, please help Wukong to figure out how many peaches are there when he starts eating on the first day?

Input

There are multiple groups of input data, each group occupies a row, including a positive integer n (1 < n < 30), which means that when there is only one peach left, it occurs on the nth day.

Output

For each group of input data, output the total number of peaches at the beginning of the first day. Each test instance takes up one line.

Sample Input

2 4

Sample Output

4 22

#include <iostream> #include <math.h> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int num(int n){ int sum=(n+1)*2; return sum; } int main(int argc, char** argv) { int n,s; while(cin>>n){ if(n<=1||n>=30) break; else{ s=1; int i =1; while(n){ if(n>1){ s=num(s); //Because it happened on the nth day when there was only one peach left. So we can't eat the last day } n--; //At this time, you can't while n --, so when IF uses n, n has changed } cout<<s<<endl; } } return 0; }

## 5.4 hdoj 2014 (average)

Problem Description

In the young singer Grand Prix, the judges will mark the contestants. The scoring rule for players is to remove a maximum score and a minimum score, and then calculate the average score. Please program the score of a player.

Input

There are multiple groups of input data, each group occupies a row, the first number of each row is n (2 < n < = 100), indicating the number of judges, and then the scores of N judges.

Output

For each group of input data, the score of the output player shall be 2 decimal places, and each group of output shall occupy one line.

Sample Input

3 99 98 97 4 100 99 98 97

Sample Output

98.00 98.50

#include <iostream> #include <iomanip> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { int num,sco,min,max; double ave; while(cin>>num){ // If (Num > 100|num < 3) {/ / do you want it or not // break; // } int n=num-2; sco=max=ave=0; min=100; while(num--){ cin>>sco; ave+=sco; if(sco<min){ min=sco; } if(sco>max){ max=sco; } } ave=ave-min-max; ave/=n; cout<<fixed<<setprecision(2)<<ave<<endl; } return 0; }

## 5.5hdoj 2015 even sum

Problem Description

There is a sequence of length n (n < = 100), which is defined as an increasing ordered even number starting from 2. Now you are required to find an average value per m in order. If the number is less than m at last, the average value is calculated by the actual number. Program the output of the average value sequence.

Input

There are multiple groups of input data, each group occupies a row, including two positive integers n and m, and the meanings of N and m are as described above.

Output

For each group of input data, output a series of average values, each group of output takes up one row.

Sample Input

3 2 4 2

Sample Output

3 6 3 7

#include <iostream> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { int m,n,a,s; while(cin>>n>>m){ a=0; s=0; while(n){ if(n<=0||m<=0){ //No judgment for positive integers break; } if(m<n){ s=0; //Less of this will add up for(int i=0;i<m;i++){ a+=2; s+=a; } cout<<s/m<<' '; //If there is a space after this, the condition for counting can only be m < n. if it is < = it is Presentation Error n-=m; } else{ s=0; for(int i=0;i<n;i++){ a+=2; s+=a; } s=s/n; cout<<s<<endl; break; } } } return 0; }

## 5.6 2016

Problem Description

Input n (n < 100) numbers, find out the minimum number, exchange it with the first number, and then output these numbers.

Input

There are several groups of input data, each group takes up one row, and the beginning of each row is an integer n, which represents the number of values of this test instance, followed by N integers. n=0 indicates the end of the input, without processing.

Output

For each group of input data, the output of each group takes up one row.

Sample Input

4 2 1 3 4 5 5 4 3 2 1 0

Sample Output

1 2 3 4 1 4 3 2 5

#include <iostream> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { int num,min,k; int n[100]; while(cin>>num){ if(num==0){ break; } else{ k=0; for(int i=0;i<num;i++){ cin>>n[i]; if(i==0){ min=n[0]; } if(min>n[i]){ min=n[i]; k=i; } } n[k]=n[0]; n[0]=min; for(int i=0;i<num-1;i++){ cout<<n[i]<<' '; } cout<<n[num-1]<<endl; } } return 0; }

## 6.1HDOJ2017 string number

Problem Description

For a given string, count the number of occurrences of numeric characters.

Input

There are multiple lines of input data. The first line is an integer n, indicating the number of test instances, followed by N lines. Each line includes a string composed of letters and numbers.

Output

For each test instance, output the number of values in the string, and each output takes up one line.

Sample Input

2 asdfasdf123123asdfasdf asdf111111111asdfasdfasdf

Sample Output

6 9

#include <iostream> #include <string.h> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { char c[2000]; int n,len; cin>>n; getchar(); while(n--){ gets(c); len = strlen(c); int count = 0 ; for(int i=0;i<len;i++){ if(c[i]-'0'<=9&&c[i]-'0'>=0){ count++; } } cout<<count<<endl; } return 0; }

## 6.2HDOJ 2018 cow story

Problem Description

There is a cow. It gives birth to a little cow every year. Each heifer starts from the fourth year and also has a heifer at the beginning of each year. How many cows are there in year n?

Input

The input data consists of multiple test cases, each of which takes up one line, including an integer n (0 < n < 55). The meaning of n is described in the title.

n=0 indicates the end of the input data, without processing.

Output

For each test case, output the number of cows at year n.

One line per output.

Sample Input

2 4 5 0

Sample Output

2 4 6

#include <iostream> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { int n;//year int a=0;//1 year old cattle int b=0;//2 year old cattle int c=0;//3 year old cattle int d=0;//4 year old cattle int sum; while(cin>>n){ a=b=c=0; d=1; if(n==0) { break; } else{ for(int i=1;i<n;i++){ //How many cows are there in year n? According to the figures, the new born cattle in the nth year are excluded d+=c;//Old cattle + aging young cattle c=b; b=a; a=d;//Fresh tender cattle sum=a+b+c+d; } cout<<sum<<endl; } } return 0; }

## 6.3HDOJ2019 inserting numbers

Problem Description

There are n (n < = 100) integers, which have been arranged in order from small to large. Now give another integer x, please insert the number into the sequence and make the new sequence still orderly.

Input

The input data contains multiple test instances, each group of data is composed of two rows, the first row is n and m, and the second row is a sequence of N numbers. N and M indicate the end of input data at the same time as 0, and this line will not be processed.

Output

For each test instance, the output is the sequence after the new element is inserted.

Sample Input

3 3 1 2 4 0 0

Sample Output

1 2 3 4

#include <iostream> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { int m,n,temp; int num[100]; while(cin>>n>>m){ if(n==0&&m==0){ //Cannot n==m==0, wrong judgment break; } for(int i=0;i<n;i++){ cin>>num[i]; } for(int i=0;i<n;i++){ if(m<num[i]){ int k=n; while(k>i){ num[k]=num[k-1]; k--; } num[i]=m; break; } } for(int i=0;i<n;i++){ cout<<num[i]<<" "; } cout<<num[n]<<endl; } return 0; }

## 6.4HDOJ 2020 absolute value ranking

Problem Description

Input n (n < = 100) integers, and output them in order of absolute value from large to small. For each test case, the absolute value of all numbers is not equal.

Input

There are multiple groups of input data, each group occupies a row, the first number of each row is n, followed by N integers, n=0 indicates the end of input data, without processing.

Output

For each test instance, the sorted results are output, with a space between the two numbers. Each test instance takes up one row.

Sample Input

3 3 -4 2 4 0 1 2 -3 0

Sample Output

-4 3 2 -3 2 1 0

#include <iostream> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int jue(int n){ //Pay attention to whether to output the absolute value after sorting the absolute value or according to the original digital value instead of the absolute value if(n>0){ return n; } else if(n<0){ n=0-n; return n; } } int main(int argc, char** argv) { int n,num,temp,flag; int sor[100]; while(cin>>n){ if(n==0) break; for(int i =0;i<n;i++){ cin>>num; sor[i]=num; } for(int i=n-1;i>=1;i--){ flag=0; for(int j=1;j<=i;j++){ if(jue(sor[j])<jue(sor[j-1])){ temp=sor[j]; sor[j]=sor[j-1]; sor[j-1]=temp; flag=1; } } if(flag==0){ for(int i=n-1;i>0;i--){ cout<<sor[i]<<' '; } cout<<sor[0]<<endl; break; } } } return 0; }

## 7.1 HDOJ 2021 salary

Problem Description

As a teacher of Hangzhou electric power, the most expected day is the 8th of every month, because this day is the day to pay wages, and it is the day to support the family

But for the staff of the school's financial department, it's a very busy day. Mr. Hu in the financial department is thinking about a question recently: if every teacher's salary is known, how many pieces of RMB should be prepared at least, so that every teacher doesn't need to change his / her salary when he / she is given the salary?

Let's assume that the salaries of teachers are all positive integers, in yuan. There are six kinds of RMB: 100 yuan, 50 yuan, 10 yuan, 5 yuan, 2 yuan and 1 yuan.

Input

The input data contains multiple test instances. The first line of each test instance is an integer n (n < 100), indicating the number of teachers, and then the salary of N teachers.

n=0 indicates the end of the input, without processing.

Output

Output an integer x for each test instance, indicating the number of RMB sheets to be prepared at least. One line per output.

Sample Input

3 1 2 3 0

Sample Output

4

#include <iostream> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int sol(int s){ int n[6]={100,50,10,5,2,1}; int x=0,a; for(int i=0;i<6;i++){ if(s>=n[i]){ x=s/n[i]; a=s%n[i]; if(a==0){ return x; } else if(a!=0){ return x+sol(a); } } } } int main(int argc, char** argv) { int n,s,sum; while(cin>>n){ if(n==0) break; sum=0; for(int i = 0;i<n;i++){ cin>>s; sum+=sol(s); } cout<<sum<<endl; } return 0; }

## 7.2 HDOJ2022 audition female host

Problem Description

Although Professor potato likes teaching very much, but under the pressure of life, she has to find a way to earn some extra money in her spare time to support her family.

"What do you do to make money? It's hard to sift the sand, and it's not handsome enough to look at the gate... " Teacher potato is helpless.

"Zhang Yimou is worse than you. How rich he is now. I heard that he is going to direct the opening ceremony of the Olympic Games! Why don't you go to the entertainment industry? " lwg is coming up with ideas.

Well, also, in order to survive, I'd better go to the entertainment circle and make a laser film Hangzhou Electric memory - back to my love right away.

Say do it, audition heroine immediately (learn from the old counselor, this can attract the media's attention, ha ha), and special provisions, the actor must have the basic skills of ac, or directly out!

Due to the good publicity of master water king, there are many MM candidates, including nit's cake sister and other high-profile beauties, even zjut's jqw dressed as a woman (fortunately recognized by security consultant HDU bin Laden and bombed away), it seems that entertainment circle is more attractive than acm

On the day of interview, there were just mn MM, standing in a mn queue. Fe(OH)2, the deputy director, scored for each MM. The scores were all 32-bit signed integers.

At first, I was wondering: how can the score still be negative? Fe(OH)2 explained that according to the selection rules, if the hair is dyed yellow, the makeup is too thick, the clothes are too little, etc., the score will be deducted. If the deduction is too much, the score may be negative. Of course, if Japanese is included in the speech, the score will be - 2147483648.

The score is coming up. It's time for me to make a decision. One of my selection principles is to choose the MM with the largest absolute interview score (which must be a 32-bit integer).

Special note: if you unfortunately choose a negative MM, it doesn't matter, because I think, if you can't attract, you should think about disgusting you.

Input

There are multiple groups of input data. The first row of each group is two integers m and N, which represent the total number of rows and columns of the candidate MM. Then there are n integers in row M. for the definition of M and N, see the description of the topic.

Output

For each group of input data, output three integers x,y and s, respectively representing the row number, column number and score of the selected MM.

note: the row number and column number start from the beginning. If there are multiple MM scores with the same absolute value, the output is the first one (that is, the one with the lowest row number, and the one with the lowest column number if the row numbers are the same).

Sample Input

2 3 1 4 -3 -7 3 0

Sample Output

2 1 -7

#include <iostream> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int jue(int n){ //Pay attention to whether to output the absolute value after sorting the absolute value or according to the original digital value instead of the absolute value if(n>0){ return n; } else if(n<0){ n=0-n; return n; } } int main(int argc, char** argv) { int m,n,score,max=0,maxj,row,col; while(cin>>m>>n){ int MM[100][100]; //My m m [M] [n], dev compiled, oj failed maxj=0; for(int i=0;i<m;i++){ for(int j=0;j<n;j++){ cin>>score; if(jue(score)>maxj){ row=i; col=j; maxj=jue(score); //To record the maximum absolute value for if comparison max=score; } } } cout<<row+1<<' '<<col+1<< ' '<<max<<endl; } return 0; }

## 7.3HDOJ2023 average score

Problem Description

Suppose that there are n (n < = 50) students in a class, and each of them takes m (m < = 5) courses. The average score of each student and the average score of each course are calculated, and the number of students whose scores of each subject are greater than or equal to the average is output.

Input

The input data has multiple test instances. The first line of each test instance includes two integers n and m, representing the number of students and courses respectively. Then there are n rows of data, each row including M integers (i.e. test scores).

Output

For each test instance, three rows of data are output, the first row contains n data, which represents the average score of n students, and the result retains two decimal places; the second row contains m data, which represents the average score of m courses, and the result retains two decimal places; the third row is an integer, which represents the number of students whose scores of each subject in the class are greater than or equal to the average score.

Each test instance is followed by a blank line.

Sample Input

2 2 5 10 10 20

Sample Output

7.50 15.00 7.50 15.00 1

#include <iostream> #include <iomanip> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { int n,m; int s[60][10]; double stu[60]; //Student double sor[6]; double sum; //curriculum int count; while(cin>>n>>m){ count = 0; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cin>>s[i][j]; } } //Average grade per course for(int i=0;i<m;i++){ sum=0; for(int j=0;j<n;j++){ sum+=s[j][i];//i is the number of students if(j==(n-1)){ sor[i]=sum/n; //i represents the course number, sum must be double, / in order for sor to be double } } } //Student average for(int i=0;i<n;i++){ sum=0; for(int j=0;j<m;j++){ sum+=s[i][j];//i decide J change, j is the course if(j==(m-1)){ stu[i]=sum/m; //i for the student } } } //Scores of all subjects are greater than or equal to the average for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(s[i][j]<sor[j]){ break; } if(j==m-1){ //The last door has been compared, indicating that the previous doors are all > average count++; } } } for(int i=0;i<n-1;i++){ cout<<fixed<<setprecision(2)<<stu[i]<<' '; } cout<<fixed<<setprecision(2)<<stu[n-1]<<endl; for(int i=0;i<m-1;i++){ cout<<fixed<<setprecision(2)<<sor[i]<<' '; } cout<<fixed<<setprecision(2)<<sor[m-1]<<endl; cout<<count<<endl<<endl; //A blank line after each test instance } return 0; }

## 7.4HDOJ2024 judge legal identifier

Problem Description

Enter a string to determine whether it is a legal identifier of C.

Input

The input data contains multiple test instances. The first row of the data is an integer n, which represents the number of test instances. Then there are n rows of input data. Each row is a string with a length of no more than 50.

Output

For each set of input data, output one row. If the input data is a legal identifier of C, "yes" is output; otherwise, "no" is output.

Sample Input

3 12ajf fi8x_a ff ai_2

Sample Output

no yes no

#include <iostream> #include <cctype> #include <string.h> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { //Identifier consists of letters, underscores and numbers, //But it must start with a letter or underscore. In addition, a keyword cannot be an identifier char s[200]; int n,flag; cin>>n; getchar(); while(n--){ gets(s); flag=1; int i=1; if(!isalpha(s[0])&& s[0]!='_'){ //Judge whether the character ch is an English letter. If it is an English letter, return non-0 (lower case is 2, upper case is 1) flag=0; } while(s[i]!='\0'&&flag==1){ if(isalnum(s[i])||s[i]=='_'){ //Judge whether the character variable c is a letter or a number, if so, return non-zero, otherwise return zero flag=1; } else{ flag=0; break; } i++; } if(flag==0){ cout<<"no"<<endl; } else if(flag==1){ cout<<"yes"<<endl; } } return 0; }

## 8.1 finding the largest element in hdoj 2025

Problem Description

For each string you enter, find the largest letter and insert the string "(max)" after it.

Input

The input data includes multiple test instances, each of which is composed of a string with a length of no more than 100 lines, and the string is only composed of upper and lower case letters.

Output

For each test instance to output a line of string, the output is the result after inserting the string "(max)". If there are multiple largest letters, insert "(max)" after each largest letter.

Sample Input

abcdefgfedcba xxxxx

Sample Output

abcdefg(max)fedcba x(max)x(max)x(max)x(max)x(max)

#include <iostream> #include <string.h> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { char s[101]; while(gets(s)){ //Spaces will be received together, and will not stop in case of spaces. gets reads string functions from the standard input device, which can read infinitely without judging the upper limit, and ends reading with carriage return int len=strlen(s); //To use the strlen function. Header file string.h, string is not allowed char max='a'; for(int i=0;i<len;i++){ if(s[i]>max){ max=s[i]; } } for(int i=0;i<len;i++){ cout<<s[i]; if(s[i]==max){ cout<<"(max)"; } } cout<<endl; } return 0; }

## 8.2HDOJ2027 digital vowel

Problem Description

Count the number of times each vowel appears in the string.

Input

The input data first includes an integer n, representing the number of test instances, and then a string of N lines with a length of no more than 100.

Output

For each test instance, output 5 lines in the following format:

a:num1

e:num2

i:num3

o:num4

u:num5

Multiple test instances are separated by a blank line.

Please note that there is no blank line after the last output:)

Sample Input

2 aeiou my name is ignatius

Sample Output

a:1 e:1 i:1 o:1 u:1 a:2 e:1 i:3 o:0 u:1

#include <iostream> #include <string.h> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { char s[101]; char y[5]={'a','e','i','o','u'}; int n; cin>>n; getchar(); while(n){ gets(s); int num[5]={0,0,0,0,0}; int len = strlen(s); for(int i=0;i<len;i++){ if(s[i]=='a'){ num[0]++; } else if(s[i]=='e'){ num[1]++; } else if(s[i]=='i'){ num[2]++; } else if(s[i]=='o'){ num[3]++; } else if(s[i]=='u'){ num[4]++; } } for(int i=0;i<5;i++){ cout<<y[i]<<":"<<num[i]<<endl; } n--; if(n!=0){ cout<<endl; } } return 0; }

## 8.3HDOJ2026 capitalize initial

Problem Description

Enter an English sentence and change the first letter of each word to uppercase.

Input

The input data contains multiple test instances. Each test instance is an English sentence with a length of no more than 100, accounting for one line.

Output

Please output the rewritten English sentences as required.

Sample Input

i like acm i want to get an accepted

Sample Output

I Like Acm I Want To Get An Accepted

#include <iostream> #include <string.h> #include <algorithm> #include <cctype> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { char s[101]; while(gets(s)){ int len=strlen(s); s[0]= toupper(s[0]); //Forget to connect the upper function with s[0] for(int i=1;i<len;i++){ while(s[i]==' '){ i++; s[i] = toupper(s[i]); //Forget to use s[i] to connect functions } } for(int i=0;i<len;i++){ cout<<s[i]; } cout<<endl; } return 0; }

## 8.4HDOJ2028 calculate the minimum common multiple of n numbers.

Problem Description

Find the least common multiple of n numbers.

Input

The input contains multiple test instances, each of which starts with a positive integer n, followed by n positive integers.

Output

Output their least common multiple for each group of test data, and the output of each test instance takes up one line. You can assume that the final output is a 32-bit integer.

Sample Input

2 4 6 3 2 5 7

Sample Output

12 70

#include <iostream> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ //1. Minimum common multiple of two numbers = product of two numbers ÷ maximum common divisor of two numbers //2. The greatest common divisor of two numbers is obtained by the division of rolling phase // 319 ÷ 377 over 319; // 377 ÷ 319 over 58; // 319 ÷ 58 over 29; // 58 ÷ 29 more than 0; // Therefore, the maximum common divisor of 319 and 377 is 29; the minimum common multiple of 319 and 377 is 319 * 377 ÷ 29 = 4147; //Greatest Common Divisor unsigned long gcd(int a,int b){ int c=a%b; while(c!=0){ a=b; b=c; c=a%b; } return b; } int main(int argc, char** argv) { unsigned long n,bei,r; ////You must use unsigned long type, and the last may be a 32-bit integer unsigned long num[1000]; while(cin>>n){ for(int i=0;i<n;i++){ cin>>num[i]; r=num[i]; if(i!=0){ bei=num[i]*num[i-1]; num[i]=gcd(num[i],num[i-1]);//num[i] is GCD num[i]=bei/num[i]; r=num[i]; //num[i] minimum common multiple } } cout<<r<<endl; } return 0; }

## 8.5HDOJ 2029 palindromes

Problem Description

"Palindrome string" is a string with the same front reading and back reading. For example, "level" or "noon" is palindrome string. Please write a program to determine whether the read string is palindrome.

Input

The input contains multiple test instances. The first row of the input data is a positive integer n, indicating the number of test instances, followed by N strings.

Output

If a string is a palindrome string, output "yes", otherwise output "no"

Sample Input

4 level abcde noon haha

Sample Output

yes no yes no

Solution 1: self writing is tedious

#include <iostream> #include <string.h> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int hui(char s[],int len){ int i,flag=1; if(len%2==0){ i=len/2-1; //Pay attention to the correspondence between array and division in palindrome string int j=i+1; while(i!=-1){ if(s[i]==s[j]){ i--; j++; flag=1; } else{ flag=0; break; } } } else{ i=len/2; int j=0; int m=0; flag=1; while(m!=-1){ j++; m=i-j; if(s[i-j]!=s[i+j]){ flag=0; break; } else{ flag=1; } } } return flag; } int main(int argc, char** argv) { int n; char s[1000]; cin>>n; getchar(); while(n--){ gets(s); int len=strlen(s); if(hui(s,len)==1){ cout<<"yes"<<endl; } else if(hui(s,len)==0){ cout<<"no"<<endl; } } return 0; }

Solution 2: simple reference

#include <stdio.h> #include <string.h> int main(){ int n; scanf("%d\n",&n); char input[1024]; bool flag; while(n--){ flag = true; gets(input); for(int i = 0;i < strlen(input)/2.0;i++){ if(input[i] != input[strlen(input)-1-i]){ printf("no\n"); flag = false; break; } } if(flag) printf("yes\n"); } return 0; }

## 9.1 HDOJ 2030 Chinese character statistics

Problem Description

Count the number of Chinese characters in a given text file.

Input

The input file first contains an integer n representing the number of test instances, followed by N paragraphs of text.

Output

For each piece of text, the number of Chinese characters is output, and the output of each test instance takes up one line.

[Hint:] considering the characteristics of internal code of Chinese character machine~

Sample Input

2 WaHaHa! WaHaHa! This year, I will not speak at the festival, but only speak Mandarin. WaHaHa! WaHaHa! Are you ready?

Sample Output

14 9

Explain

I think it's necessary for me to talk about this problem. It's very new for me, because I haven't dealt with the problem of Chinese characters. Before dealing with this problem, we need to understand the representation of the internal code of the Chinese character machine in the computer.

First of all, we all know that because the computer was invented by the Americans, ASCII code can only be used to store English, and ASCII only takes up one byte. Then how can Chinese characters be represented by computer? At this time, it is proposed to use two bytes to store Chinese characters and other characters, the highest position of each byte is 1, and computers are stored by complement code, which means Chinese characters Every byte of is a negative number, so to find the number of Chinese characters is to find the number of less than 0 in the string and then divide by 2

Answer

#include <iostream> #include <string.h> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { int n,num; char s[1000]; cin>>n; getchar(); while(n--){ num=0; gets(s); int len=strlen(s); for(int i=0;i<len;i++){ if(s[i]<0){ num++; } } cout<<num/2<<endl; } return 0; }

## 9.2 HDOJ 2032 Yanghui triangle

Problem Description

Do you remember the Yanghui triangle you learned in middle school? The specific definition will not be described here. You can refer to the following figures:

1

1 1

1 2 1

1 3 3 1

1 4 6 4 1

1 5 10 10 5 1

Input

The input data contains multiple test instances, and the input of each test instance only contains a positive integer n (1 < = n < = 30), indicating the number of layers of Yanghui triangle to be output.

Output

For each input, please output the Yanghui triangle of corresponding layers. The integers of each layer are separated by a space, and a blank line is added after each Yanghui triangle.

Sample Input

2 3

Sample Output

1 1 1 1 1 1 1 2 1

#include <iostream> #include <string.h> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { int n; int tr[32][32]; //At the beginning, tr[30][30] defined here, the following for array is out of bounds and doesn't know it while(cin>>n){ for(int i=0;i<30;i++){ for(int j=0;j<30;j++){ tr[i][j]=0; } } if(n==1){ cout<<1<<endl<<endl; continue; } // Yang Hui triangle for(int i=0;i<n;i++){ tr[i][0]=1; for(int j=1;j<=i+1;j++){ tr[i+1][j]=tr[i][j-1]+tr[i][j]; } } cout<<1<<endl;//The following for cannot output tr[0] [0] for(int i=1;i<n;i++){ for(int j=0;j<i;j++){ cout<<tr[i][j]<<' '; } cout<<tr[i][i]<<endl; } cout<<endl; } return 0; }

## 9.3 HDOJ 2040 affinity number

Problem Description

Pythagoras, the ancient Greek mathematician, found in the study of natural numbers that the sum of all the true divisors (that is, not their own divisors) of 220 is:

1+2+4+5+10+11+20+22+44+55+110＝284.

All the true divisors of 284 are 1, 2, 4, 71, 142, which add up to 220. People are surprised at this number and call it affinity number. Generally speaking, if any one of the two numbers is the sum of the true divisors of the other, then the two numbers are affinity numbers.

Your task is to write a program to determine whether the given two numbers are affinity numbers

Input

The first row of input data contains a number M, followed by a M row, each row has an instance, including two integers A,B; where 0 < = A,B < = 600000;

Output

For each test instance, if A and B are affinity numbers, output YES; otherwise, output NO.

Sample Input

2 220 284 100 200

Sample Output

YES NO

#include <iostream> #include <math.h> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int y(int a,int b, int flag){ int s1=1,s2=1; for(int i =2;i<a;i++){ if(a%i==0){ s1+=i; } } for(int i =2;i<b;i++){ if(b%i==0){ s2+=i; } } if(s1==b&&s2==a){ flag=1; }else { flag=0; } return flag; } int main(int argc, char** argv) { int n; int a,b,flag; cin>>n; getchar(); while(n--){ cin>>a>>b; if(y(a,b,flag)==1){ cout<<"YES"<<endl; } else{ cout<<"NO"<<endl; } } return 0; }

## 9.4HDOJ 2042 difficult Series II

Problem Description

Because old Xu didn't have money, the toll collector took half of his sheep, saw the old man's tears rippling, hesitated for a moment, and returned one to him. Coincidentally, every toll station in the back took half of the sheep at that time and returned one. When the old man arrived at the market, only three sheep were left.

You, the young people with conscience, can you help to figure out how many sheep the old man had in the first place?

Input

The first row of input data is an integer n, which is composed of N rows below. Each row contains an integer a (0 < a < = 30), indicating the number of toll stations.

Output

For each test instance, please output the initial number of sheep, one line for each test instance.

Sample Input

2 1 2

Sample Output

4 6

#include <iostream> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { int n,m,x,sum; cin>>n; getchar(); while(n--){ cin>>m; x=sum=3; for(int i=0;i<m;i++){ sum=(x-1)*2; x=sum; } cout<<sum<<endl; } return 0; }

## 9.5 HDOJ 2055 AN EASY PROBLEM

Problem Description

we define f(A) = 1, f(a) = -1, f(B) = 2, f(b) = -2, ... f(Z) = 26, f(z) = -26;

Give you a letter x and a number y , you should output the result of y+f(x).

Input

On the first line, contains a number T.then T lines follow, each line is a case.each case contains a letter and a number.

Output

for each case, you should the result of y+f(x) on a line.

Sample Input

6 R 1 P 2 G 3 r 1 p 2 g 3

Sample Output

19 18 10 -17 -14 -4

#include <iostream> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { char c; int n,m; cin>>n; getchar(); while(n--){ cin>>c>>m; if('a'<=c&&c<='z'){ cout<<'a'-c-1+m<<endl; } else if('A'<=c&&c<='Z'){ cout<<c-'A'+1+m<<endl; } } return 0; }

## 10.1HDOJ1050 mobile table (greedy algorithm)

Lesson of tears and blood: don't set too many variables, it's very easy to confuse

Idea: map the rooms on both sides of the corridor to a location (because they are essentially a location when moving a table). In this way, map to a one-dimensional coordinate system, loop through, and the place with the most passes can be pushed to the time

Problem Description

The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure.

The floor has 200 rooms each on the north side and south side along the corridor. Recently the Company made a plan to reform its system. The reform includes moving a lot of tables between rooms. Because the corridor is narrow and all the tables are big, only one table can pass through the corridor. Some plan is needed to make the moving efficient. The manager figured out the following plan: Moving a table from a room to another room can be done within 10 minutes. When moving a table from room i to room j, the part of the corridor between the front of room i and the front of room j is used. So, during each 10 minutes, several moving between two rooms not sharing the same part of the corridor will be done simultaneously. To make it clear the manager illustrated the possible cases and impossible cases of simultaneous moving.

For each room, at most one table will be either moved in or moved out. Now, the manager seeks out a method to minimize the time to move all the tables. Your job is to write a program to solve the manager's problem.

Input

The input consists of T test cases. The number of test cases ) (T is given in the first line of the input. Each test case begins with a line containing an integer N , 1<=N<=200 , that represents the number of tables to move. Each of the following N lines contains two positive integers s and t, representing that a table is to move from room number s to room number t (each room number appears at most once in the N lines). From the N+3-rd line, the remaining test cases are listed in the same manner as above.

Output

The output should contain the minimum time in minutes to complete the moving, one per line.

Sample Input

3 4 10 20 30 40 50 60 70 80 2 1 3 2 200 3 10 100 20 80 30 50

Sample Output

10 20 30

#include <iostream> #include <string.h> #include <math.h> #include <cstring> #include <cstdio> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { int T,n,s1,t1,ro[405],s,t;//ro stands for the original appearance, s,t stands for moving from s to t; int temp,max; cin>>T; getchar(); while(T--) { cin>>n; getchar(); for(int i=0; i<405; i++) { ro[i]=0; //Initialize the number of passes } max=0; for(int i=0; i<n; i++) { cin>>s>>t; if(s>t) { //Make the moving start room smaller than the end point temp=s; s=t; t=temp; } s=(s+1)/2; t=(t+1)/2; for( int j=s; j<=t; j++) { ro[j]++; if(ro[j]>max) { //The maximum number of passes * 10 is the minimum time required max=ro[j]; } } } cout<<max*10<<endl; } return 0; }

## 10.2HDOJ1051 stick problem (greedy algorithm)

The next stick is longer and heavier than the previous one. Otherwise, the machine will restart

Ideas: 1. Define the length and weight of the structure record for the wood stick, and customize the comp function to arrange the wood stick according to the length from small to large, and compare the length according to the weight

**2. Two for circulation screens drop one stick which is lighter than the previous one (the heavy one passes without restarting, mark the Stick-1, which means it has been used), and mark the number of restarts with sum**

Problem Description

There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs some time, called setup time, for the machine to prepare processing a stick. The setup times are associated with cleaning operations and changing tools and shapes in the machine. The setup times of the woodworking machine are given as follows:

(a) The setup time for the first wooden stick is 1 minute.

(b) Right after processing a stick of length l and weight w , the machine will need no setup time for a stick of length l' and weight w' if l<=l' and w<=w'. Otherwise, it will need 1 minute for setup.

You are to find the minimum setup time to process a given pile of n wooden sticks. For example, if you have five sticks whose pairs of length and weight are (4,9), (5,2), (2,1), (3,5), and (1,4), then the minimum setup time should be 2 minutes since there is a sequence of pairs (1,4), (3,5), (4,9), (2,1), (5,2).

Input

The input consists of T test cases. The number of test cases (T) is given in the first line of the input file. Each test case consists of two lines: The first line has an integer n , 1<=n<=5000, that represents the number of wooden sticks in the test case, and the second line contains n 2 positive integers l1, w1, l2, w2, ..., ln, wn, each of magnitude at most 10000 , where li and wi are the length and weight of the i th wooden stick, respectively. The 2n integers are delimited by one or more spaces.

Output

The output should contain the minimum setup time in minutes, one per line.

Sample Input

3 5 4 9 5 2 2 1 3 5 1 4 3 2 2 1 1 2 2 3 1 3 2 2 3 1

Sample Output

2 1 3

#include <iostream> #include <vector> #include <algorithm> #include <math.h> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ struct wo { int l; int w; }; bool comp(wo a,wo b ) { //Sort the sticks according to L. If l is the same, compare w if(a.l!=b.l) return a.l<b.l; else return a.w<b.w; } int main(int argc, char** argv) { int t,n,l,w; wo wood[5005]; cin>>t; getchar(); while(t--) { cin>>n; getchar(); int i=0; for(int i=0;i<n;i++){ cin>>wood[i].l>>wood[i].w; } sort(wood,wood+n,comp); //Sort by cmp int min,sum=0; for(int j=0;j<n;j++){ if(wood[j].w!=-1){ //wood[i].w==-1 means that this stick has been used min=wood[j].w; sum++; for(int k=j+1;k<n;k++){ if(wood[k].w>=min&&wood[k].w!=-1){ min=wood[k].w; wood[k].w=-1; } } } } cout<<sum<<endl; } return 0; }

Sample Output

10 20 30

#include <iostream> #include <string.h> #include <math.h> #include <cstring> #include <cstdio> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char** argv) { int T,n,s1,t1,ro[405],s,t;//ro stands for the original appearance, s,t stands for moving from s to t; int temp,max; cin>>T; getchar(); while(T--) { cin>>n; getchar(); for(int i=0; i<405; i++) { ro[i]=0; //Initialize the number of passes } max=0; for(int i=0; i<n; i++) { cin>>s>>t; if(s>t) { //Make the moving start room smaller than the end point temp=s; s=t; t=temp; } s=(s+1)/2; t=(t+1)/2; for( int j=s; j<=t; j++) { ro[j]++; if(ro[j]>max) { //The maximum number of passes * 10 is the minimum time required max=ro[j]; } } } cout<<max*10<<endl; } return 0; }

## 10.3HDOJ1051 stick problem (greedy algorithm)

The next stick is longer and heavier than the previous one. Otherwise, the machine will restart

Ideas: 1. Define the length and weight of the structure record for the wood stick, and customize the comp function to arrange the wood stick according to the length from small to large, and compare the length according to the weight

**2. Two for circulation screens drop one stick which is lighter than the previous one (the heavy one passes without restarting, mark the Stick-1, which means it has been used), and mark the number of restarts with sum**

Problem Description

There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs some time, called setup time, for the machine to prepare processing a stick. The setup times are associated with cleaning operations and changing tools and shapes in the machine. The setup times of the woodworking machine are given as follows:

(a) The setup time for the first wooden stick is 1 minute.

(b) Right after processing a stick of length l and weight w , the machine will need no setup time for a stick of length l' and weight w' if l<=l' and w<=w'. Otherwise, it will need 1 minute for setup.

You are to find the minimum setup time to process a given pile of n wooden sticks. For example, if you have five sticks whose pairs of length and weight are (4,9), (5,2), (2,1), (3,5), and (1,4), then the minimum setup time should be 2 minutes since there is a sequence of pairs (1,4), (3,5), (4,9), (2,1), (5,2).

Input

The input consists of T test cases. The number of test cases (T) is given in the first line of the input file. Each test case consists of two lines: The first line has an integer n , 1<=n<=5000, that represents the number of wooden sticks in the test case, and the second line contains n 2 positive integers l1, w1, l2, w2, ..., ln, wn, each of magnitude at most 10000 , where li and wi are the length and weight of the i th wooden stick, respectively. The 2n integers are delimited by one or more spaces.

Output

The output should contain the minimum setup time in minutes, one per line.

Sample Input

3 5 4 9 5 2 2 1 3 5 1 4 3 2 2 1 1 2 2 3 1 3 2 2 3 1

Sample Output

2 1 3

#include <iostream> #include <vector> #include <algorithm> #include <math.h> using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ struct wo { int l; int w; }; bool comp(wo a,wo b ) { //Sort the sticks according to L. If l is the same, compare w if(a.l!=b.l) return a.l<b.l; else return a.w<b.w; } int main(int argc, char** argv) { int t,n,l,w; wo wood[5005]; cin>>t; getchar(); while(t--) { cin>>n; getchar(); int i=0; for(int i=0;i<n;i++){ cin>>wood[i].l>>wood[i].w; } sort(wood,wood+n,comp); //Sort by cmp int min,sum=0; for(int j=0;j<n;j++){ if(wood[j].w!=-1){ //wood[i].w==-1 means that this stick has been used min=wood[j].w; sum++; for(int k=j+1;k<n;k++){ if(wood[k].w>=min&&wood[k].w!=-1){ min=wood[k].w; wood[k].w=-1; } } } } cout<<sum<<endl; } return 0; }