week2 experiment A

Meaning of the questions:
Here Insert Picture Description
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 job is an alkane group 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 I understand.
Input:
Group Number T behavior data input of the first (1≤T≤200000). 5 each data lines of two integers a, b (1≤a, b≤6, a ≤b) data guarantee, alkanyl is entered one of five or more.
Output:
each data output line, English name representative of an alkane group.
INPUT the Sample:
2
. 1 2
2. 3
. 3. 4
. 4. 5
. 5. 6
. 1. 4
2. 3
. 3. 4
. 4. 5
. 5. 6
the Sample Output:
n-Hexane-
. 3-Methylpentane
Thinking:
Enter the number of the group to be determined, because each line of input has two ends. By storing two arrays, inputs the left and right points points. Because there are six endpoints, the point when the left or right end point of 1 or 2 or 3 or 4 or 5 or 6, the number of occurrences stored in another endpoint array. In the judgment of the number of times the power fails. Can be obtained by analyzing the n-hexane is six occurrences endpoint 1,2,2,2,2,1; 2-methylpentane six occurrences endpoint is 1,1,3,2,2,1; 3-methylpentane six occurrences endpoint is 1,1,3,2,2,1; 2-2-dimethylbutane six occurrences endpoint is 1,1,1,1,2,4,2; 3-dimethylbutane six endpoints appear the number is 1,1,1,1,3,3. Can be found in the number of 3-methylpentane and 2-methylpentane six two endpoints appears the same, so then a further determination can be found in 3-methylpentane occurrence count is three endpoints, the number of endpoints connected thereto is occurring 1,2,2. 2-methylpentane and 3 times the number of occurrences of the endpoint, the number of endpoints connected thereto is occurring 1,1,2. Further judged by the difference can be determined alkane five different groups.
Code:
#include
the using namespace STD;
int main ()
{
int m;
CIN >> m;
// for (int I = 0; I <m; I ++)
the while (M-)
{
int left [. 5] = {0 };
int right [. 5] = {0};
for (int J = 0; J <. 5; J ++)
{
cin>>left[j]>>right[j];
}
//int an=0,bn=0,cn=0,dn=0,en=0,fn=0;
int v[10]={0};
int count1=0,count2=0,count3=0,count4=0;
int sum1=0,sum2=0;
for(int k=0;k<5;k++)
{
if(left[k]1||right[k]1)
v[1]++;
/if(left[k]==1)
//an++;
v[1]++;
if(right[k]==1)
v[1]++;
/
if(left[k]2||right[k]2)
//bn++;
v[2]++;
if(left[k]3||right[k]3)
//cn++;
v[3]++;
if(left[k]4||right[k]4)
//dn++;
v[4]++;
if(left[k]5||right[k]5)
//en++;
v[5]++;
if(left[k]6||right[k]6)
//fn++;
v[6]++;
/if(left[k]==2)
//an++;
v[2]++;
if(right[k]==2)
v[2]++;
if(left[k]==3)
//an++;
v[3]++;
if(right[k]==3)
v[3]++;
if(left[k]==4)
//an++;
v[4]++;
if(right[k]==4)
v[4]++;
if(left[k]==5)
//an++;
v[5]++;
if(right[k]==5)
v[5]++;
if(left[k]==6)
//an++;
v[6]++;
if(right[k]==6)
v[6]++;
/
}
for(int i=1;i<7;i++)
{
//if(an
1 || bn
1||cn
1||dn
In 1 ||
1||fn
1)
if(v[i]1)
count1++;
//else if(an
2 || bn
2||cn
2||dn
In 2 ||
2||fn
2)
if(v[i]2)
count2++;
//else if(an
3 || bn
3||cn3||dnIn 3 ||3||fn3)
if(v[i]3)
count3++;
//else if(an
4 || bn4||cn4||dnIn 4 ||4||fn4)
if(v[i]4)
count4++;
}
/*if(an
1 || bn
1||cn1||dnIn 1 ||1||fn1)
count1++;
else if(an2 || bn2||cn2||dnIn 2 ||2||fn2)
count2++;
else if(an3 || bn3||cn3||dnIn 3 ||3||fn3)
count3++;
else if(an4 || bn4||cn4||dnIn 4 ||4||fn4)
count4++;*/

if(count12&&count24)
cout<<“n-hexane”<<endl;
else if(count14&&count32)
cout<<“2,3-dimethylbutane”<<endl;
else if(count14&&count21&&count41)
cout<<“2,2-dimethylbutane”<<endl;
else if(count1
3&&count22&&count31)
{
int temp;
/if(an3)
temp=1;
else if(bn
3)
temp=2;
else if(cn3)
temp=3;
else if(dn
3)
temp=4;
else if(en3)
temp=5;
else if(fn
3)
temp=6;
/
for(int i=1;i<7;i++)
{
//if(tempv[i])
if(v[i]3)
temp=i;
}
for(int i=1;i<7;i++)
{
/*if(left[i]temp)
{
int cmp=right[i];
//if((cmp=2&&bn
1)||(cmp
3&&cn
1)||(cmp4&&dn1)||(cmp5&&en1)||(cmp6&&fn1)||(cmp1&&an1))
//if((cmp=2&&v[2]1)||(cmp3&&v[3]1)||(cmp4&&v[4]1)||(cmp5&&v[5]1)||(cmp6&&v[6]1)||(cmp1&&v[1]1))
if(v[cmp]1)
sum1++;
//else if((cmp
1&&an
2)||(cmp2&&bn2)||(cmp3&&cn2)||(cmp4&&dn2)||(cmp5&&en2)||(cmp6&&fn2))
//else if((cmp1&&v[1]2)||(cmp2&&v[2]2)||(cmp3&&v[3]2)||(cmp4&&v[4]2)||(cmp5&&v[5]2)||(cmp6&&v[6]2))
//if(v[cmp]2)
// sum2++;
}
if(right[i]temp)
{
int cnp=left[i];
//if((cnp=2&&bn
1) || (CNP
3&&cn
1) || (CNP
4&&dn1) || (CNP5&&en1) || (CNP6&&fn1) || (CNP1&&an==1))
//if((cnp=2&&v[2]1) || (CNP3&&v[3]1) || (CNP4&&v[4]1) || (CNP5&&v[5]1) || (CNP6&&v[6]1) || (CNP1&&v[1]==1))
if(v[cnp]1)
sum1++;
//else if((cnp
1&&v[1]2) || (CNP2&&v[2]2) || (CNP3&&v[3]2) || (CNP4&&v[4]2) || (CNP5&&v[5]2) || (CNP6&&v[6]==2))
//if(v[cnp]==2)
// sum2++;
}

}
if(sum12)
cout<<“2-methylpentane”<<endl;
else if(sum1
1)
cout<<“3-methylpentane”<<endl;*/
//}
int pi[3]={0};
int t=0;
for(int i=0;i<5;i++)
{
if(left[i]==temp)
{
pi[t]=right[i];
t++;
}
if(right[i]==temp)
{
pi[t]=left[i];
t++;
}
}
int b[3]={0};
while(t–)
{
for(int i=0;i<5;i++)
{
if(left[i]==pi[t])
{
b[t]++;
}
if(right[i]pi[t])
{
b[t]++;
}
}
}
int b1=0;
for(int i=0;i<3;i++)
{
if(b[i]1)
b1++;
}
if(b1
2) cout<<“2-methylpentane”<<endl;
if(b1
1) cout<<“3-methylpentane”<<endl;

}
}

//cout<<“nm”;
return 0;
}

Published 19 original articles · won praise 0 · Views 220

Guess you like

Origin blog.csdn.net/weixin_45117273/article/details/104738504