[Programming thinking and practice Week2 chemistry experiment A]

Meaning of the questions:

Here Insert Picture Description

The figure is a chemical structure of an alkane group, the alkane group has 6 atoms and chemical bonds five, six atoms numbered 1 to 6, with a pair of numbers a, b represents a chemical bond between atoms a and the atom b.
Thus, with five pairs of numbers may represent a group of alkanes. Our mission is paraffin-based screening categories (Figure five). Atoms no specific reference means, such as (1,2), (2,3), (3,4), (4,5), (5,6) and (1,3), (2,3), (2,4), (4,5), (5,6) is essentially the same, are the alkane groups.

Input:

Enter the number of groups T (1≤T≤200000) a first behavioral data. 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.

Simple Input:2

1 2
2 3
3 4
4 5
5 6
1 4
2 3
3 4
4 5
5 6

Output:

Each set of data, an output line, the English name of the representative alkanyl

Simple Output:

n-hexane
3-methylpentane

Ideas:

Because there is no fixed form of numerals, it is not starting from a reference point, i.e., a bond should start from the relationship between the dots, the number of chemical bonds is constant, different types of alkanyl occur because of the different categories of a the number of different chemical bonds atom, i.e. a different number of atoms atom, can be found through the observation, one atom between atoms and having at least one chemical bond, and up to four atoms chemically bonded, so, we create a there are six elements of the array, the number of atoms per atom save, and then calculate the number of connections are 1,2,3,4 atoms. If the number of connections is the number of atoms of 4 to 1, compared to 2,2-dimethylbutane; 4 if the number of connections is the absence of connections is the number of atoms of 3 to 2, for the 2,3-dimethylbutane; if the number of connections the total number of atoms connecting all adjacent atom number of 2 to 4 was n-hexane, if the number of connections is the number of atoms of 3 to 1, it is necessary with different situations, wherein the atom (atomic number of connection 3) is 5, compared with 3-methylpentane; otherwise, for the 2-methylpentane.

Code:

#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;

void judge(int *num[])
{
	int a[7];
	memset(a,0,sizeof(int)*7);
	for(int i=0;i<5;i++)
	{
		a[num[i][0]]++;
		a[num[i][1]]++;
	}
	int c[5];
	memset(c,0,sizeof(int)*5);
	for(int i=1;i<7;i++)
	{
		int temp=a[i];
		c[temp]++;
	}
	if(c[4]==1)
	{
		printf("%s\n","2,2-dimethylbutane");
	}
	if(c[3]==2)
	{
		printf("%s\n","2,3-dimethylbutane");
	}
	if(c[2]==4)
	{
		printf("%s\n","n-hexane");
	}
	if(c[3]==1)
	{
		int temp;
		for(int i=1;i<=6;i++)
		{
			if(a[i]==3)
			{
				temp=i;
				break;
			}
		}
		int number=0;
		for(int i=0;i<5;i++)
		{
			if(num[i][0]==temp)
				number+=a[num[i][1]];
			if(num[i][1]==temp)
				number+=a[num[i][0]];
		}
		if(number==5)
			printf("%s\n","3-methylpentane");
		else
			printf("%s\n","2-methylpentane");
		
	}
}
int main(int argc, char** argv) {
	int n;
	int**num=new int*[5];
	for(int i=0;i<5;i++)
		num[i]=new int[2];
	
	scanf("%d",&n);
	getchar();
	for(int i=0;i<n;i++)
	{
		for(int i=0;i<5;i++)
		{
			scanf("%d %d",&num[i][0],&num[i][1]);
			getchar();
		}
		judge(num);
	}
	return 0;
}
Published 25 original articles · won praise 8 · views 547

Guess you like

Origin blog.csdn.net/weixin_44034698/article/details/104633874