Week2 A - Chemistry

Week2 A - chemical
chemistry is amazing, the following is an alkane groups.

FIG assumed above, the alkane group has 6 atoms and chemical bonds 5, reference numeral 6 atoms respectively, 1 to 6, followed by a pair of numbers a, b represents a chemical bond between atoms a and the atom b. Thus by line 5 a, b can be described as a alkanyl

Your task is paraffin-based screening category.

No atom numbering, 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, in fact, there is no relationship between the number, you can draw on paper to understand the
input
group number T (1≤T≤200000) enter the first line of data. 5 per group of data lines of two integers a, b (1≤a, b≤6, a ≤b)

Guaranteed data input alkane group is one of 5 or more

Output
each data output line, English name of the representative alkanyl

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

Using an array of recording
with the maximum number of connections is determined

#include<iostream>
using namespace std;
int main(){
	int a;
	cin>>a;
	int b1[5],b2[5];
	int c[7],pp[7];
	for(int i=0;i<a;i++){//输入
		for(int j=0;j<7;j++){c[j]=0;pp[j]=0;
		}
		cin>>b1[0]>>b2[0];
		cin>>b1[1]>>b2[1];
		cin>>b1[2]>>b2[2];
		cin>>b1[3]>>b2[3];
		cin>>b1[4]>>b2[4];
		for(int y=1;y<=6;y++){
			for(int u=0;u<5;u++){
				if(b1[u]==y)c[y]++;
			}
			for(int u=0;u<5;u++){
				if(b2[u]==y)c[y]++;
			}
		} 
		int yy=0;
		int point=0;
		//计算出每个图形中最大连接数yy
		for(int y=1;y<7;y++){
			if(c[y]==4){yy=4;break;
			}else if(c[y]==3){point=y;
				yy++;
			}
		}
		for(int y=1;y<7;y++){
			if(c[y]==1){pp[y]=1;
			}
		}
		int t=0;
		//for(int p=1;p<7;p++)cout<<p<<"p="<<c[p]<<endl;
		//用最大连接数yy判断
		if(yy==4){cout<<"2,2-dimethylbutane"<<endl;
		}else if(yy==2){cout<<"2,3-dimethylbutane"<<endl;
		}else if(yy==1){for(int h=0;h<5;h++){
		//2-methylpentane跟3-methylpentane有同样的最大连接数 要再进行判断
			if(b1[h]==point&&pp[b2[h]]==1){t++;
			}else if(b2[h]==point&&pp[b1[h]]==1){t++;
			}
		}
		if(t==2){cout<<"2-methylpentane"<<endl;
		}else{cout<<"3-methylpentane"<<endl;
		}
		}else if(yy==0){cout<<"n-hexane"<<endl;
		}
	}
} 
Released four original articles · won praise 0 · Views 21

Guess you like

Origin blog.csdn.net/qq_43324189/article/details/104672124