A - Chemistry
Title Description
Chemistry is amazing. Here are alkanes.
Suppose, as shown in the figure above, this alkane group has 6 atoms and 5 chemical bonds, 6 atoms are labeled 1-6 respectively, and then a pair of numbers a and b indicate that there is a chemical bond between atom A and atom b. In this way, 5 lines a and b can describe an alkane group. Your task is to identify the alkane group.
There is no numbering method for atoms, such as
1 2
2 3
3 4
4 5
5 6
and
1 3
2 3
2 4
4 5
5 6
It's the same. It's essentially a chain. The number doesn't matter. You can draw on paper
Input
Input the group number T of the first row of data (1 ≤ t ≤ 200000). Each group of data has 5 rows, each row is two integers a,b (1 ≤ a,b ≤ 6,a ≤ b)
Data guarantee that the input alkane group is one of the above five;
Output
Each group of data, output one line, representing the English name of alkane
Sample Input
2
1 2
2 3
3 4
4 5
5 6
1 4
2 3
3 4
4 5
5 6
Sample Output
n-hexane
3-methylpentane
Solving problems
Characteristics of five alkane HDMG
n - hexane -- the atom x 2 of one chemical bond; the atom x 4 of two chemical bonds;
2,2 - dimethylbutane -- the atom of one chemical bond x 4; the atom of two chemical bonds x 1; the atom of four chemical bonds x 1;
2,3 - dimethylbutane -- the atom x 4 of one chemical bond; the atom x 2 of three chemical bonds;
2 - methylpentane and 3 - methylpentane -- the atom of one chemical bond x 3; the atom of two chemical bonds x 2; the atom of three chemical bonds x 1;
The key point of judgment is to connect with 2-methylentane and 3-methylentane:
For 2 - methylentane: the atom with three chemical bonds, one of the atoms connected with it has a chemical bond number of 1;
For 3 - methylentane: the atom with three chemical bonds, two of the atoms connected with it have a chemical bond number of 1;
d [] and s [] and x [] []
d [] is used to store the number of chemical bonds from atoms 1 to 5;
s [] is used to store the number of each chemical bond;
x [] [] is used to store the connection between atoms, that is, the number of atoms connected on both sides of a chemical bond;
Judgement method
According to the characteristics of five alkane HDMG, it mainly involves the number of target chemical bonds in s [];
For 2-METHYLPENTANE and 3-methylpentane, we record the number of chemical bonds of the adjacent atoms whose number of chemical bonds is 3 by visiting x [], and use count to record the number of chemical bonds of 1 in the adjacent atoms; count = 1 is 3-methylpentane; count = 2 is 2-METHYLPENTANE;
Problem solving code
#include <iostream> #include <vector> using namespace std; int a, b; int x[5][2]; int main() { int T; while (cin>>T) { for (int l = 0; l < T; l++) { int d[] = {0, 0, 0, 0, 0, 0}; int s[] = {0, 0, 0, 0}; for (int m = 0; m < 5; m++){ cin>>a>>b; d[a-1]++; d[b-1]++; x[m][0] = a; x[m][1] = b; } for (int c = 0; c < 6; c++) s[d[c] - 1]++; if (s[0] == 2 && s[1] == 4) { cout<<"n-hexane"<<endl; continue; } if (s[0] == 4 && s[1] == 1 && s[3] == 1) { cout<<"2,2-dimethylbutane"<<endl; continue; } if (s[0] == 4 && s[2] == 2) { cout<<"2,3-dimethylbutane"<<endl; continue; } if (s[0] == 3 && s[1] == 2 && s[2] == 1) { int z = 0; int count = 0; for (int w = 0; w < 6; w++) { if (d[w] == 3) { z = w; break; } } for (int e = 0; e < 5; e++) { for (int r = 0; r < 2; r++) { if (x[e][r] == z + 1 && r == 0 && d[x[e][r+1] - 1] == 1) count++; if (x[e][r] == z + 1 && r == 1 && d[x[e][r-1] - 1] == 1) count++; } } if (count == 1) cout<<"3-methylpentane"<<endl; if (count == 2) cout<<"2-methylpentane"<<endl; continue; } } } }
B - explode zero (×) and work hard (√)
Title Description
The real-time evaluation system used in programming thinking assignments and experiments has the characteristics of timely achievement ranking. How is its function realized?
After we have worked hard to finish the procedure that we can't bear to look directly at and submit it, the evaluation system will either return AC or return various other errors. No matter what kind of error method, it will always write a note to you, indicating that you have been cheated here. When you go through thousands of difficulties and finally AC it, it will calculate a general ledger with you, indicating that this problem has been submitted several times in total.
In the long river of years, although you have passed more and more questions, the time you spent passing each question (from the beginning to the time when you passed the question) will be recorded as the trace of your struggle. In particular, for the questions you pass, every time you submit a mistake about this question, you will be counted as a certain unit time penalty. In this way, you may be ahead of others in the number of questions you make, but in the number of people who make the same questions, you may be at a disadvantage in the ranking due to the high penalty time.
For example, there are eight questions (A,B,C,D,E,F,G,H) in an exam. Each person's question has a number mark under the corresponding question number. A negative number indicates the number of times the student has submitted errors on the question, but there is no AC up to now. A positive number indicates the time taken by AC. if a positive number keeps up with a pair of brackets, there is a positive number b in it, It means that the student AC took the time a and submitted b times by mistake. Examples can be found in the sample input and output section below.
Input
The input data includes multiple lines. The first line is the number of common questions n (1 ≤ n ≤ 12) and the unit penalty time m (10 ≤ m ≤ 20). Each line of data after that describes the information of a student. First, the user name of the student (a string of no more than 10 characters) is followed by the score status of all n questions. The description uses the format of the number mark in the problem description, as shown in the table above.
Output
According to the scores of these students, output a real-time ranking. It is obvious that the real-time ranking is first arranged according to the number of AC questions, the most in the first place, and then according to the number of time points, and the least in the first place. If it happens that the first two are equal, it is arranged according to the dictionary order of names, and the small in the first place. Each student takes one line, outputs the name (10 characters wide), the number of questions made (2 characters wide, right aligned) and the time minute (4 characters wide, right aligned). There is a space between the name, the number of questions and the time minute. Data can be output according to the required output format.
Sample Input
8 20 GuGuDong 96 -3 40(3) 0 0 1 -8 0 hrz 107 67 -3 0 0 82 0 0 TT 120(3) 30 10(1) -3 0 47 21(2) -2 OMRailgun 0 -99 -8 0 -666 -10086 0 -9999996 yjq -2 37(2) 13 -1 0 113(2) 79(1) -1 Zjm 0 0 57(5) 0 0 99(3) -7 0
Sample Output
TT 5 348 yjq 4 342 GuGuDong 3 197 hrz 3 256 Zjm 2 316 OMRailgun 0 0
Solving problems
Processing of input information
The input of one line includes the name and the scores of each question. I cut one line into two parts, the name is a part, and then the score is a part. Because the number of questions is known, a for cycle can be used to analyze the situation of each question;
Handling of achievements
1. Directly skip negative number without processing;
2. A non negative number (without parentheses) stores each bit in the array, records the number of bits at the same time, and obtains the time score of the question;
3. Non negative numbers (with brackets) first store all the numbers before "(" into the array for processing and recording, then empty the array, then calculate the data in brackets, and add the two to get the time score of the problem;
Output format
cout<<setw(n)<<left/right<<element; // n determines the element length of the output; left/right determines whether the output format is left aligned or right aligned;
Problem solving code
#include <iostream> #include <cstdio> #include <algorithm> #include <string> #include <iomanip> #include <vector> #include <cmath> using namespace std; int n, m; vector<int> score; //Everyone in the grade vector<string> s; //Every result struct s_i{ string name; int AN = 0; int TS = 0; }; bool PX(s_i A, s_i B){ if (A.AN == B.AN) { if (A.TS == B.TS) { return A.name < B.name; } return A.TS < B.TS; } return A.AN > B.AN; } int main() { cin>>n>>m; string i1; vector<s_i> Rank; while (cin>>i1) { s_i A; A.name = i1; string i2; for (int l = 0; l < n; l++) { cin>>i2; s.push_back(i2); } for (int l = 0; l < n; l++) { int s1 = 0, s2 = 0; string d = s[l]; string::iterator w = d.begin(); while (w != d.end()) { if (*w == '-') break; if (*w >= '0' && *w <= '9') score.push_back(*w - '0'); if (*w == '(') { long int t = score.size(); for (long int f = 0; f < score.size(); f++) { s1 = s1 + pow(10, t - 1) * score[f]; t--; } score.clear(); } if (*w == ')') { long int t = score.size(); for (long int f = 0; f < score.size(); f++) { s2 = s2 + pow(10, t - 1) * m * score[f]; t--; } score.clear(); } w++; } if (score.size() != 0) { long int t = score.size(); for (long int f = 0; f < score.size(); f++) { s1 = s1 + pow(10, t - 1) * score[f]; t--; } score.clear(); } A.AN++; int ss = s1 + s2; if (ss == 0) A.AN--; A.TS = A.TS + ss; } Rank.push_back(A); s.clear(); } sort(Rank.begin(), Rank.end(), PX); for (long int v = 0; v < Rank.size(); v++) { cout<<setw(10)<<left<<Rank[v].name<<" "; cout<<setw(2)<<right<<Rank[v].AN<<" "; cout<<setw(4)<<right<<Rank[v].TS; cout<<endl; } Rank.clear(); }
C-ruishen playing cards
Title Description
Ruishen HRZ is bored at home because of the epidemic. At the same time, he is very fierce. All his classes are water and water can get A +, so he is bored. He finds three other people: gugudong, TENGSHEN and zjm to play cards (the world's bitter Ruishen has been for A long time).
Obviously, the game is made up of four people in a circle. We call the four directions North, Southeast and West. The corresponding English is North, East, South, West. The game consists of 52 playing cards. At first, we appointed a dealer (one in the southeast and northwest, marked with English initials) to start licensing. The order of licensing was clockwise. The first dealer did not issue himself, but issued his next person (the next person clockwise). That way, everyone gets 13 cards.
Now we define the order of cards. First of all, the decor is (plum blossom) < (square piece) < (spade) < (red peach). (when inputting, we use C,D,S,H to represent plum blossom, square piece, spade, and red peach respectively, that is, the initial of the word). For deck values, we specify 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < T < J < Q < K < a.
Now, as God, you have to sort everyone's cards from small to large and output them in a given format. (see output description and sample output for specific format).
Input
Input contains multiple sets of data
The first line of each set of data contains an uppercase character indicating who the dealer is. If the character is' × ', it means the end of input.
Next there are two lines, each with 52 characters, representing 26 cards, and the two lines add up to 52 cards. Each card consists of two characters. The first character represents the decor and the second character represents the value.
Output
Output multiple groups of data licensing results, each group of data after the need to output an additional blank line!!!!!
Each group of data should be composed of 24 lines. The output should be clockwise and always output south first As a result of player, each player first outputs one line, namely player name (southeast, northwest), then five lines, the first line and the fifth line output fixed format (see the example), the second line and the fourth line output values in order and format (see the example), and the third line output patterns in order and format (see the example).
Sample Input
N CTCAH8CJD4C6D9SQC7S5HAD2HJH9CKD3H6D6D7H3HQH4C5DKHKS9 SJDTS3S7S4C4CQHTSAH2D8DJSTSKS2H5D5DQDAH7C9S8C8S6C2C3 #
Sample Output
South player: +---+---+---+---+---+---+---+---+---+---+---+---+---+ |6 6|A A|6 6|J J|5 5|6 6|7 7|9 9|4 4|5 5|7 7|9 9|T T| | C | C | D | D | S | S | S | S | H | H | H | H | H | |6 6|A A|6 6|J J|5 5|6 6|7 7|9 9|4 4|5 5|7 7|9 9|T T| +---+---+---+---+---+---+---+---+---+---+---+---+---+ West player: +---+---+---+---+---+---+---+---+---+---+---+---+---+ |2 2|5 5|9 9|K K|5 5|7 7|9 9|4 4|T T|J J|A A|8 8|A A| | C | C | C | C | D | D | D | S | S | S | S | H | H | |2 2|5 5|9 9|K K|5 5|7 7|9 9|4 4|T T|J J|A A|8 8|A A| +---+---+---+---+---+---+---+---+---+---+---+---+---+ North player: +---+---+---+---+---+---+---+---+---+---+---+---+---+ |3 3|4 4|J J|2 2|3 3|T T|Q Q|K K|8 8|Q Q|K K|2 2|3 3| | C | C | C | D | D | D | D | D | S | S | S | H | H | |3 3|4 4|J J|2 2|3 3|T T|Q Q|K K|8 8|Q Q|K K|2 2|3 3| +---+---+---+---+---+---+---+---+---+---+---+---+---+ East player: +---+---+---+---+---+---+---+---+---+---+---+---+---+ |7 7|8 8|T T|Q Q|4 4|8 8|A A|2 2|3 3|6 6|J J|Q Q|K K| | C | C | C | C | D | D | D | S | S | H | H | H | H | |7 7|8 8|T T|Q Q|4 4|8 8|A A|2 2|3 3|6 6|J J|Q Q|K K| +---+---+---+---+---+---+---+---+---+---+---+---+---+
Solving problems
Determine the rank order of position, decor and brand value
String array wanjia [], huase [] and paizhi [] store player position, suit and card value in the specified size order respectively, and return the size order according to the value of suit and card value through the user-defined functions RankW, rankh and rankz;
Process input information
The first input must be the position information of the start of licensing, which is processed separately and stored with a global variable b;
The information entered later will be processed according to its length. If the length is 1, it may be the start of the next round of licensing operation, or the end of the game, so before this, it is necessary to output all the cards obtained by each person according to the specified rules; if the length is greater than 1, read from the beginning, read two bytes each time, according to b to get the location information of the next player obtaining the card, read two at a time , and then enter the next two, b + +;
Problem solving code
#include <iostream> #include <cstdio> #include <algorithm> #include <string> #include <iomanip> #include <vector> #include <cmath> using namespace std; string wanjia[] = {"N", "E", "S", "W"}; char huase[] = {'C', 'D', 'S', 'H'}; char paizhi[] = {'2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'}; int RankW(string w){ for (int n = 0; n < 4; n++) { if (w == wanjia[n]) {return n;} } return 5; } int RankH(char h){ for (int n = 0; n < 4; n++) { if (h == huase[n]) {return n;} } return 5; } int RankZ(char z){ for (int n = 0; n < 13; n++) { if (z == paizhi[n]) {return n;} } return 14; } struct pai { char HS; char PZ; pai() {} pai(char a, char b) {HS = a; PZ = b;} }; bool PX (pai a, pai b) { if (RankH(a.HS) != RankH(b.HS)) return RankH(a.HS) < RankH(b.HS); else return RankZ(a.PZ) < RankZ(b.PZ); } vector<pai> N; vector<pai> E; vector<pai> S; vector<pai> W; void input(int a, pai p) { if (a == 0) {N.push_back(p); return;} if (a == 1) {E.push_back(p); return;} if (a == 2) {S.push_back(p); return;} if (a == 3) {W.push_back(p); return;} } void output(vector<pai> s) { cout<<"+---+---+---+---+---+---+---+---+---+---+---+---+---+"<<endl; cout<<"|"; for (int n = 0; n < 13; n++) {cout<<s[n].PZ<<" "<<s[n].PZ<<"|";} cout<<endl<<"|"; for (int n = 0; n < 13; n++) {cout<<" "<<s[n].HS<<" "<<"|";} cout<<endl<<"|"; for (int n = 0; n < 13; n++) {cout<<s[n].PZ<<" "<<s[n].PZ<<"|";} cout<<endl; cout<<"+---+---+---+---+---+---+---+---+---+---+---+---+---+"<<endl; } string Poker; int b; pai p; int main() { cin>>Poker; b = (RankW(Poker) + 1) % 4; while (cin>>Poker) { if (Poker.size() == 1) { sort(S.begin(), S.begin() + 13, PX); sort(W.begin(), W.begin() + 13, PX); sort(N.begin(), N.begin() + 13, PX); sort(E.begin(), E.begin() + 13, PX); cout<<"South player:"<<endl; output(S); S.clear(); cout<<"West player:"<<endl; output(W); W.clear(); cout<<"North player:"<<endl; output(N); N.clear(); cout<<"East player:"<<endl; output(E); E.clear(); cout<<endl; if (Poker == "#") return 0; else { b = (RankW(Poker) + 1) % 4; continue; } } for (int n = 0; n < 51; n = n + 2) { p.HS = Poker[n]; p.PZ = Poker[n+1]; input(b, p); b = (b + 1) % 4; } } return 0; }