题目
https://vjudge.net/problem/Gym-270437A
题目大意
本题为一道模拟题,题目给定戊烷中的化学键,不同碳原子用1~6的数字来表示,要求判断这是哪一种戊烷。由于每种戊烷中有五个化学键,因此输入只给定输入组数,每次输出对应的英文名称。题目已经给出不同结构戊烷和其对应的名称,对应关系如图。
解题思路
本题较为简单,对于n-hexane和2,2-dimethylbutane这两种只需要判断其中连接化学键数目最多的碳原子连接了几个化学键即可,在输入时便可以做好对应的记录,二者分别对应1、4。2,3-dimethylbutane因为结构特殊,含有两个连接三条化学键的碳原子,也很好区分。至于剩下两种,结构比较相似,判断方法是观察与含三个化学键的碳原子所连接的三个碳原子包含的化学键数目。如图可知2-methylpentane连接了两个含一个化学键和一个含两个化学键的碳原子,3-methylpentane连接了两个含两个个化学键和一个含一个化学键的碳原子。在输入时只要记录每个编号的原子连接的对象,对于结构中只有一个连接了三个碳原子的结构,根据以上判别方法即可区分。
具体代码
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include<cstdlib>
#include<ctime>
#include<iomanip>
#define ll long long
#define FOR(i,a,n) for(register int i=a;i<n;i++)
#define RF(i,a,n) for(register int i=a;i>n;i--)
#define NIL -1
using namespace std;
int num[10],ans[10];
int main()
{
int n;
cin >> n;
for(int i = 0; i < n; i++)
{
int a,b,flag = 0;
vector<int> ss[10];
memset(num,0,sizeof(num));
memset(ans,0,sizeof(ans));
for(int j = 1; j < 6; j++)
{
cin >> a >> b;
num[a]++;
num[b]++;
ss[a].push_back(b);
ss[b].push_back(a);
}
for(int j = 1; j < 7; j++)
{
if(num[j] == 3)
{
int aaa = 0;
for(int k = 0; k < 3; k++)
{
if(num[ss[j][k]] == 1)
{
aaa++;
}
}
if(aaa == 2)
{
flag = 1;
}
}
ans[num[j]]++;
}
if(ans[2] == 4)
{
cout << "n-hexane" << endl;
}
else if(ans[3] == 2)
{
cout << "2,3-dimethylbutane" << endl;
}
else if(ans[4] == 1)
{
cout << "2,2-dimethylbutane" << endl;
}
else if(flag == 1)
{
cout << "2-methylpentane" << endl;
}
else
{
cout << "3-methylpentane" << endl;
}
}
return 0;
}