题目描述
化学很神奇,以下是烷烃基。
假设如上图,这个烷烃基有6个原子和5个化学键,6个原子分别标号1~6,然后用一对数字 a,b 表示原子a和原子b间有一个化学键。这样通过5行a,b可以描述一个烷烃基
你的任务是甄别烷烃基的类别。
原子没有编号方法,比如
1 2
2 3
3 4
4 5
5 6
和
1 3
2 3
2 4
4 5
5 6
是同一种,本质上就是一条链,编号其实是没有关系的,可以在纸上画画就懂了。
Input
输入第一行为数据的组数T(1≤T≤200000)。每组数据有5行,每行是两个整数a, b(1≤a,b≤6,a ≤b) ;
数据保证,输入的烷烃基是以上5种之一Output每组数据,输出一行,代表烷烃基的英文名。
Output
每组数据,输出一行,代表烷烃基的英文名。
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
解题思路
通过输入的数字统计1到6每个数字的出场次数(度),根据此特性判断:
1.最大出场次数(最大的度)为2的,即为n-hexane;
2.最大出场次数(最大的度)为4的,即为2,2-dimethylbutane;
3.出场次数(度)为3的点的个数为2,则为2,3-dimethylbutane;
4.出场次数(度)为3的点的相邻点,如果其中2个是度为1的点,则为2-methylpentane;只有1是度为1的点,为3-methylpentane。
完整代码
#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
int a[5];
int b[5];
int c[6];
for(int l=0;l<t;l++)
{
for(int m=0;m<7;m++)
{c[m]=0;}
for(int i=0;i<5;i++)
{cin>>a[i]>>b[i];
}
for(int i=1;i<7;i++)
{for(int l=0;l<5;l++)
if(i==a[l]||i==b[l])
{
c[i]++;}}//得到了各个数字出场次数
int max=0;
for(int i=1;i<7;i++)
{
if(c[i]>max)
max=c[i];
}
if(max==2)
{cout<<"n-hexane"<<endl;
continue;}
else if(max==4)
{cout<<"2,2-dimethylbutane"<<endl;
continue;}
else
{
int times=0;
for(int i=1;i<7;i++)
if(c[i]==3)
times++;
if(times==2)
{cout<<"2,3-dimethylbutane"<<endl;
continue;}
int p=0;
for(int i=1;i<7;i++)
{if(c[i]==3)
{p=i;
break;}}
int d[3];
d[0]=0;
d[1]=0;
d[2]=0;
int l=0;
for(int i=0;i<5;i++)
{
if(a[i]==p)
{d[l]=b[i];
l++;}
if(b[i]==p)
{d[l]=a[i];
l++;}}
int k[3];
k[0]=0;
k[1]=0;
k[2]=0;
for(int i=0;i<3;i++)
for(int l=0;l<5;l++)
{if(a[l]==d[i]||b[l]==d[i])
k[i]++;}
int time=0;
for(int i=0;i<3;i++)
{ if(k[i]==1)
time++;}
if(time==1)
{cout<<"3-methylpentane"<<endl;
continue;}
else
{cout<<"2-methylpentane"<<endl;
continue;}
}
} }