PAT_B_1059_C language contest

Subject description:

C language contest is a fun competition hosted by Zhejiang University School of Computer Science. Since the subject is race for fun, award rules will develop very funny: 

0, the winner will win a "mystery prize" (such as a very huge student research papers ......). 
1 ranking for the prime number of students will win the best prizes - small yellow man doll! 
2, others will get chocolate. 
Given the game's final ranking and a series of entrants ID, you have to give these contestants should get the prize. 

Input format: 
input of the first row is given a positive integer N (≤10000), a number of participants. Then given final rankings N rows, each row gives an entrant ID (4 digits) ranking order. Next we are given a positive integer K and the K ID to be queried. 

Output formats: 
output ID in a row for each ID to be queried: prizes, or prizes which are Mystery Award (mystery prize), or the Minion (small yellow people), or Chocolate (chocolate). If the ID check is simply not ranked in print Are you kidding? (I'm playing it?). If the ID has been checked up (ie prizes already received over), print ID: Checked (can not eat too much of). 

Sample input: 
. 6 
1111 
6666 
8888 
1234 
5555 
0001 
. 6 
8888 
0001 
1111 
2222 
8888 
2222 
Output Sample:
8888: Minion
0001: Chocolate
1111: Mystery Award
2222: Are you kidding?
8888: Checked
2222: Are you kidding?

Answer key:

// Key: digital formatted output control 
// integer of 1, as will be output in the format 0001 
19 // output takes the following format control, is relatively simple, does not have to control the output string 
( "% 04d \ n" printf , val );

 I AC Code:

Improvement The following code:

	@ 5 represents a grand prize, representing small yellow people 3, represents chocolate; // int Class [Max] = {0} 
	// the number is prime, is determined for each digital high redundancy, then the award determination of the number corresponding to 
	int prime = 0; // set the parameter indicates whether the location is a prime number
// 1059 C language contest 
@ Key: formatting the digital control output 
# the include <stdio.h> 
# the include <math.h> 
# 10001 Max DEFINE 
int Prime (int); 
int main (void) 
{ 
	int the Num [ max]; 
	int In Flag [max] = {0}; // -1 Representative collar flattering 
	int Class [max] = {0 }; // 5 on behalf of the grand prize, representing small yellow people 3, represents chocolate 
	int len1, LEN2, I, J, N, Val; 
	int TEMP = 0; // set parameters, temp = 0, representing no found, temp = 1, the representative found 
	
	Scanf ( "% D", & N); 
	LEN1 = N; 
	for ( I =. 1; I <= LEN1; I ++) 
	{ 
		Scanf ( "% D", & the Num [I]); 
		IF (. 1 == Prime (I)) 
			Class [I] =. 3; 
		the else 
			Class [I] =. 1; 
	} 
	Class [. 1] =. 5; 

	Scanf ( "% D", & N); 
	LEN2 = N;
	for (I =. 1; I <= LEN2; I ++) i++)
	{
		TEMP = 0; 
		Scanf ( "% D", & Val); 
		// exhaustive searching in the Num [] array Val 
		for (J =. 1; J <= LEN1; J ++ ) 
		{ 
			IF (the Num [J] == Val) 
			{ 
				TEMP = 1; // flag is set to 1, indicating found 
				BREAK; 
			} 
		} 
		// if found, leading through comparison whether a prize 
		if (1 == temp) 
		{ 
			// collar over the prize 
			IF (In Flag == -1 [J]) 
			{ 
				the printf ( "% 04D: the Checked \ n-", Val); 
			 } 
			 // did not receive 
			 the else IF (In Flag == 0 [J]) 
			 { 
			 	IF (Class. 5 == [J]) 
			 	{ 
			 		the printf ( "% 04D: Mystery Award \ n-", Val); 
				 } 
				 the else IF (Class. 3 == [J]) 
				 {
				 	the printf ( "% 04D: Minion \ n-", Val); 
				 } 
				 the else IF (Class. 1 == [J]) 
				 { 
				 	the printf ( "% 04D: Chocolate \ n-", Val); 
				 } 
			 	// set flag collar after winning is -1 
			 	In Flag [J] = -1; 
			 } 
			
		 } 
		// otherwise you kidding output Are? 
		the else 
		{ 
			the printf ( "% 04D: Are you kidding \ n-?", Val); 
		} 
	} 
	return 0; 
} 

int Prime ( n-int) 
{ 
	int I = 2; 
	
	for (I; I <= sqrt (n-); I ++) 
	{ 
		IF (n-I% == 0) 
			return 0; 
	} 
	return. 1; 
} 

Guess you like

Origin www.cnblogs.com/Robin5/p/11208094.html