Week2 experiment

Chemical A-

Subject to the effect

Screening hydrocarbon-based categories

Resolution:

FIG careful observation found that the degree of each node may be recorded, classified according to the degree of:

According to the number of free nodes 2/3/4
view of Class 2 and Class 3 degrees are 1 2 1 2 3 1, 3 degrees of nodes connected to node 3 and then by finding, if it is 1 12, compared to the second category, if it is 221, for the class 3

Source:

#include <cstdio>
#include <iostream>
//#include <vector> 
#include <cstring>
#include <string> 
using namespace std;
int a[7];
int b[5];
int G[7][7];
string s[5] = {{"n-hexane"},{"2-methylpentane"},{"3-methylpentane"},{"2,3-dimethylbutane"},{"2,2-dimethylbutane"}};

int dif()
{
	if(b[4] == 1) return 4;
    if(b[3] == 2) return 3;
	if(b[2] == 4) return 0;
	else
	{
		int p;

		for(int i = 1; i <= 6; i++)//p为度是3的点 
		 if(a[i] == 3) p = i;
		int c[4] = {0};
		int n = 1;
		for(int i = 1; i <= 6; i++)
		{
			if(G[i][p] == 1 || G[p][i] == 1)
			{
				c[n++] = i; 
			}
		}
		int o[4] = {0};
		for(int i=0;i<4;i++)
		{
			o[a[c[i]]]++;
		}
	
		if(o[1] == 2) return 1;
		else return 2;
	}

}

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		for(int i=0;i<7;i++)/*初始化数组*/
	    {
	    	a[i]=0;
		}
	    
	    for(int i=0;i<5;i++)/*初始化数组*/
	    {
	    	b[i]=0;
		}
	    
	    for(int i=0;i<7;i++)/*初始化数组*/
	    {
	    	for(int j=0;j<7;j++)
	    	   G[i][j]=0;
		}
		int x,y;
		for(int i = 1; i <= 5; i++)
		{
			scanf("%d%d",&x,&y);
			G[x][y] = 1;a[x]++;a[y]++;
		}
		for(int i = 1; i <= 6; i++)
			b[a[i]]++;
		int t = dif();
		cout << s[t] << "\n";
	}
	return 0;
}

B - burst zero (×) vigorously miracle (√)

Subject to the effect

According to the list given, the output of a real-time ranking. Real-time ranking with AC number of the first keyword (in descending order), when the penalty for the second keyword (ASC), the name of the third key (in ascending order).

answer

By observing the data, we found that scores each question we can read separately.
Scanf reading can be taken and then processed strings embodiment, may also be used sscanf (s, "% d ( % d)", x, y) is performed.
It is a sort multiple conditions. Their order of priority:
(1) made out in descending subject
(including penalty time) (2) Time spent in ascending
(3) the name lexicographically ascending
source

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

struct STU
{
    char name[20];
    int ac;
    int cnt;
} s[1000];

int cmp(STU x,STU y)//先按题数排,再按总时间小的在头排序
{
    if(x.cnt!=y.cnt)
        return x.cnt>y.cnt;
    return x.ac<y.ac;
}

int main()
{
    int n,t;
    while(~scanf("%d%d",&n,&t))
    {
        int i,j,k = 0;
        char sc[100];
        while(~scanf("%s",s[k].name))
        {
            s[k].ac = s[k].cnt = 0;
            for(i = 0; i<n; i++)
            {
                scanf("%s",sc);
                if(!strcmp(sc,"0"))//没提交,自然不算
                    continue;
                if(sc[0] == '-')//提交的都是错的,而且没A,也不算
                    continue;
                s[k].cnt++;
                int len = strlen(sc),f = 0,l = 0;
                if(!strstr(sc,"("))//没有括号代表1A,,直接算
                {
                    while(sc[l])
                    {
                        f = f*10+sc[l]-'0';
                        l++;
                    }
                    s[k].ac+=f;
                    continue;
                }
                while(sc[l]!='(')//有括号就要算出提交的时间
                {
                    f = f*10+sc[l]-'0';
                    l++;
                }
                s[k].ac+=f;
                f = 0;
                l++;
                while(sc[l]!=')')//罚时
                {
                    f = f*10+sc[l]-'0';
                    l++;
                }
                f = f*t;
                s[k].ac+=f;
            }
            k++;
        }
        sort(s,s+k,cmp);
        for(i = 0; i<k; i++)
        {
            printf("%-10s%3d%5d\n",s[i].name,s[i].cnt,s[i].ac);
        }
    }

    return 0;
}

C - Swiss god cards (do not support C ++ 11, G ++ and C ++ compilers try to submit Ha)

Given order and starting card dealer.
Cards defined order, first color is C <D <S <H. For values of the sign face, we require 2 <3 <4 <5 < 6 <7 <8 <9 <T <J <Q <K <A.
According to the given format output cards hit the small hands of each player.

Analysis:
for sequential DRAW, licensing may be implemented in the order of 4% through the cycle, when the DRAW, definition of the structure in which there are two variables char, i.e., the size and color of the brand store, reading every two characters, by two functions, namely the read incoming characters into the number corresponding size. Overload <, i.e., the first color according to ascending order, then according to the magnitude of the output cards.

Source


#include<stdio.h>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
char s[1000];
int start;
struct TT
{
	char x,y;
	TT();
	TT(char x,char y):x(x),y(y){};
};
 
int check(char c)
{   switch (c)
			{
				case 'C':return 0; break;
				case 'D':return 1; break;
				case 'S':return 2; break;
				case 'H':return 3; break;
			}
	
}
 
int get(char c)

{   switch (c)
			{
				case 'T':return 10; break;
				case 'J':return 11; break;
				case 'Q':return 12; break;
				case 'K':return 13; break;
				case 'A':return 14; break;
			}
	
	return c-'0';
}
 
bool cmp(const TT &a,const TT &b)
{
	if (a.x==b.x) return get(a.y)<get(b.y);
	return check(a.x)<check(b.x);
}
 
vector<TT> a[4];
 
int main()
{
	int f=0;
	while (~scanf("%s",s))
	{
		if (s[0]=='#') break;
		if (f) printf("\n"); else f=1;
		if (s[0]=='E') start=0;
		if (s[0]=='S') start=1;
		if (s[0]=='W') start=2;
		if (s[0]=='N') start=3;
		
		for (int i=0;i<4;i++) a[i].clear();
		scanf("%s",s);
		scanf("%s",s+52);
		for (int i=0;i<104;i+=2,start=(start+1)%4)
		a[start].push_back(TT(s[i],s[i+1]));
		for (int i=0;i<4;i++) 
		sort(a[i].begin(),a[i].end(),cmp);
		for (int i=0;i<4;i++)
		{   
			switch (i)
			{
				case 0:printf("South player:\n"); break;
				case 1:printf("West player:\n"); break;
				case 2:printf("North player:\n"); break;
				case 3:printf("East player:\n"); break;
			}
			printf("+---+---+---+---+---+---+---+---+---+---+---+---+---+\n");
			for (int j=0;j<a[i].size();j++)
			{
				printf("|%c %c",a[i][j].y,a[i][j].y);
				if (j==a[i].size()-1) printf("|\n");
			}
			for (int j=0;j<a[i].size();j++)
			{
				printf("| %c ",a[i][j].x);
				if (j==a[i].size()-1) printf("|\n");
			}
			for (int j=0;j<a[i].size();j++)
			{
				printf("|%c %c",a[i][j].y,a[i][j].y);
				if (j==a[i].size()-1) printf("|\n");
			}
			printf("+---+---+---+---+---+---+---+---+---+---+---+---+---+\n");
		}
	}
	return 0;
}

Released two original articles · won praise 0 · Views 14

Guess you like

Origin blog.csdn.net/qq_43636442/article/details/104683333