A-Chemistry
Chemistry is amazing. Here are the alkyl groups.
Suppose, as shown above, this alkyl group has six atoms and five chemical bonds, six atoms labeled 1-6, and then a pair of numbers a and b denotes that there is a chemical bond between atom A and atom b.This allows a description of an alkyl group in line a,b
Your task is to identify the categories of alkyl groups.
Atoms have no numbering methods, such as
1 2
2 3
3 4
4 5
5 6
and
1 3
2 3
2 4
4 5
5 6
Is the same, is essentially a chain, the number actually has no relationship, you can draw on paper to understand
Input inputs the number of groups of data for the first behavior T (1 < T < 200000).Each set of data has five rows, each of which is two integers a,b (1 < a,b < 6,a < b)
Data guarantees that the input alkyl group is one of the five above Output sets of data, with one output line representing the English name of the alkyl group Example
Input
2
1 2
2 3
3 4
4 5
5 6
1 4
2 3
3 4
4 5
5 6
Output
n-hexane
3-methylpentane
Solving problems
The numeric number of the atom is meaningless, and the reason for the difference in alkyl groups is that the degrees of the points are different.The total number of points is not too many. When input, save each point and the points it connects into a graph, and record the number of points each point connects (simulation questions using stl vector s are good, but I am used to opening two-dimensional arrays), then judge by the rules in the diagram.Note that the words must not be misspelled, or it will be very hard and painful to find them!
#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <cmath> #include <iomanip> #include <algorithm> using namespace std; #define ll long long int vis[10][10]; int deg[10]; int maxdeg; int main() { int T; cin>>T; for(int i=1;i<=T;i++) { memset(vis,0, sizeof(vis)); memset(deg,0, sizeof(deg)); maxdeg = 0; int a,b; for(int j=1;j<=5;j++) { cin>>a>>b; deg[a]++; deg[b]++; maxdeg = max(maxdeg,deg[a]); maxdeg = max(maxdeg,deg[b]);//Maximum can tell a lot vis[a][deg[a]] = b; vis[b][deg[b]] = a;//Undirected graph } /*for(int j=1;j<=6;j++) { cout<<deg[j]<<" "; } cout<<"\n";*/ if(maxdeg == 4) { printf("2,2-dimethylbutane\n"); continue; } if(maxdeg == 2) { printf("n-hexane\n"); continue; } if(maxdeg == 3) { int cnt1=0,cnt2=0,cnt3=0; for(int j=1;j<=6;j++) { if(deg[j] == 3) { for(int k=1;k<=3;k++) { if(deg[vis[j][k]] == 3)cnt3++; if(deg[vis[j][k]] == 2)cnt2++; if(deg[vis[j][k]] == 1)cnt1++; } break; } } if(cnt1 == 2 && !cnt3) { printf("2-methylpentane\n"); continue; } if(cnt2 == 2) { printf("3-methylpentane\n"); continue; } if(cnt3) { printf("2,3-dimethylbutane\n"); continue; } } } return 0; }
Blast zero (*) and work miracles hard ()
The real-time evaluation system used in the thought job and experiment of program design is characterized by timely ranking of results. How is its function implemented?
After we have worked so hard to look straight into the program and submitted it, the system either returns AC or other errors. Whatever the wrong method, it will always write a note to you indicating that you have been pitted here. After you have worked so hard to get it AC, it will calculate a general ledger with you indicating that the problem has been submitted incorrectly several times.
Over the years, you've passed more and more questions, but the time you spend on each question (from the very beginning to the time you passed) is recorded as a sign of your struggle.In particular, each incorrect submission you made about the topic you passed will be counted as a unit time penalty. As a result, you may be ahead of others in the number of questions you have made, but among those who have made the same number of questions, you may be at a disadvantage in ranking because of the high penalty time.
For example, in an exam, there are eight questions (A,B,C,D,E,F,G,H). Each person's questions are marked by a number under the corresponding title. Negative numbers indicate the number of incorrect submissions that the student has made on the question but has not yet had AC. Positive numbers indicate the time taken by AC. If positive numbers a follow a pair of parentheses, there is a positive number b in them.It means that the student ACed this question, which took a long time and submitted it b times incorrectly.The example can be seen in the sample input and output section below.
Input
The input data contains multiple rows, the first row is the common number of questions n (1 < n < 12) and the unit penalty m (10 < m < 20). After that, each row of data describes a student's information. First, the student's user name (no more than 10 characters of string) is followed by the score status of all n questions. The description is in the format of quantity markers in question description, as shown in the table above.
Output
Output a real-time ranking based on the students'score status.Real-time ranking apparently starts with the number of AC questions, more in the first place, and then in the number of time points, less in the first place. If the first two items happen to be equal, they are sorted by the dictionary of names, the smaller in the first place.Each student takes one line, outputs the name (10 characters wide), the number of questions (2 characters wide, right-aligned) and the time (4 characters wide, right-aligned).There is a space between the name, the number of questions and the time.The data is guaranteed to be output in 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
It is not difficult for students familiar with acm competition system to understand the meaning of this topic. This topic is essentially a multi-keyword sorting by custom rules. The first keyword is the number of passing questions, and the second keyword is the time penalty.
However, the difficulty of this topic is not in the collation, but in the data entry and preprocessing to calculate penalties.When reading, encounter a failing question (0 or -n) and skip directly, otherwise the ac number is added and the penalty hours are handled with a process similar to Read-in optimization.
The last sort is over!
#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <cmath> #include <iomanip> #include <algorithm> using namespace std; #define ll long long struct student { string name; int ac; int tm; }a[10005]; int getnum(char c) { int num = 0; bool flag = 0; while (!isdigit(c)) { if(c == '-')flag = 1; c = getchar(); } while(isdigit(c)) { num = num*10 + c - '0'; c = getchar(); } return flag? -num : num; } bool cmp(student x,student y) { if(x.ac != y.ac) { return x.ac > y.ac; } if(x.tm != y.tm) { return x.tm < y.tm; } return x.name < y.name; } int main() { int n,m,k=0; string s0; cin>>n>>m; while(cin>>s0) { a[++k].name = s0; for(int i=1;i<=n;i++) { string s; cin>>s; int cnt = 0; if((s[0] == '0') || (s[0] == '-'))//No problem, no problem { continue; } int j=0; a[k].ac++; while(j<s.length()) { while(isdigit(s[j])) { cnt = cnt*10 + s[j] - '0'; ++j; } if(s[j] == '(') { int was = 0; ++j; while(isdigit(s[j])) { was = was*10 + s[j] - '0'; ++j; } cnt+=was*m; ++j; } } a[k].tm += cnt; } } sort(a+1,a+k+1,cmp); for(int i=1;i<=k;i++) { cout<<left<<setw(10)<<a[i].name<<" "; cout<<setiosflags(ios::right)<<setw(2)<<a[i].ac<<" "; cout<<setiosflags(ios::right)<<setw(4)<<a[i].tm<<"\n"; } return 0; }
Rui Shen Plays Cards
Raytheon HRZ was bored because he was idle at home and at the same time he was very bad. All the classes were water and he could get A+. So he was bored and got three other people: Googu Dong, Teng Shen and zjm to play cards (the world has been bitter and Rui Shen for a long time).
Obviously, the board is made up of four people, in a circle.We call the four directions north, south, East and west.The corresponding English is North, East, South, West.The game consists of a set of 52 cards.To begin, we assign a dealer (one in the southeast and northwest, identified by the English initials) to start the deal in a clockwise order, where the first dealer does not issue himself but his next person (the next one clockwise).That way, everyone gets 13 cards.
Now we define the order of the cards. First of all, the colors are (clubs)< (diamonds)< (spades)< (hearts). (When entering, we use C,D,S,H to represent clubs, diamonds, spades, hearts, which are the first letters of the word.)For face values, we specify 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < T < J < Q < K < A.
Now that you are God, you have to sort each person's cards from smallest to largest and output them in the given format.(See output description and sample output for specific format).
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
This issue is very vivid, the output looks very complex, in fact, there are more whistles in the flowers.Let's save the cards in order, and then sort them.
#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <cmath> #include <iomanip> #include <algorithm> using namespace std; #define ll long long struct pokers { char color; char num; }player[4][15]; string s1,s2; int thecolor[101]; int thenum[101]; void give(int head) { int i=0,pos=0; while(i < s1.length()) { player[head][pos].color = s1[i]; player[head][pos].num = s1[i+1]; player[(head+1)%4][pos].color = s1[i+2]; player[(head+1)%4][pos].num = s1[i+3]; player[(head+2)%4][pos].color = s1[i+4]; player[(head+2)%4][pos].num = s1[i+5]; player[(head+3)%4][pos].color = s1[i+6]; player[(head+3)%4][pos].num = s1[i+7]; ++pos; i+=8; } } bool cmp(pokers a,pokers b) { if(a.color != b.color) { return thecolor[a.color] < thecolor[b.color]; } else return thenum[a.num] < thenum[b.num]; } void print(int head) { for(int i=0;i<12;i++) { printf("|%c %c",player[head][i].num,player[head][i].num); } printf("|%c %c|\n",player[head][12].num,player[head][12].num); for(int i=0;i<12;i++) { printf("| %c ",player[head][i].color,player[head][i].color); } printf("| %c |\n",player[head][12].color,player[head][12].color); for(int i=0;i<12;i++) { printf("|%c %c",player[head][i].num,player[head][i].num); } printf("|%c %c|\n",player[head][12].num,player[head][12].num); printf("+---+---+---+---+---+---+---+---+---+---+---+---+---+\n"); } int main() { char st; thecolor['H'] = 4; thecolor['S'] = 3; thecolor['D'] = 2; thecolor['C'] = 1; for(int i=2;i<=9;i++)thenum[i+'0'] = i; thenum['T'] = 10; thenum['J'] = 11; thenum['Q'] = 12; thenum['K'] = 13; thenum['A'] = 14; while(1) { cin>>st; if(st == '#')break; //memset(player,0, sizeof(player)); cin>>s1>>s2; s1+=s2; if(st == 'E')give(0); if(st == 'S')give(1); if(st == 'W')give(2); if(st == 'N')give(3); for(int i=0;i<=3;i++) { sort(player[i],player[i]+13,cmp); } printf("South player:\n+---+---+---+---+---+---+---+---+---+---+---+---+---+\n"); print(0); printf("West player:\n+---+---+---+---+---+---+---+---+---+---+---+---+---+\n"); print(1); printf("North player:\n+---+---+---+---+---+---+---+---+---+---+---+---+---+\n"); print(2); printf("East player:\n+---+---+---+---+---+---+---+---+---+---+---+---+---+\n"); print(3); printf("\n"); } return 0; }