PAT B 1041 (C ++) - Long brush brother's title path

1041 exam seat number (15 points)
each PAT candidates will be assigned seat number two at the time of the exam, the test machine is a seat, a seat is exam. Under normal circumstances, the first candidates in the admission test machine to obtain a seat number, the seating state into the test machine, the system displays the seat number of the candidate for an examination, the examination candidates need to change the test to take the seat. But some candidates late, test machine has ended, they can only receive the test machine took the seat numbers turn to you, find out their examination seat number from the background.

Input format:
input of the first row is given a positive integer N (≤1000), followed by N rows, each row of a given candidate information: ticket number test machine test seat number seat number. Wherein the ticket number from the 16-bit numbers, numbered from 1 to N seat. Enter the ticket number to ensure that everyone is different, and no time will two people assigned to the same seat.
After the candidate information, gives a positive integer M (≤N), followed by analysis of the M test machine to be queried row seat number, separated by a space.

Output format:
the corresponding seat number for each test machine need to query, in the row corresponding to the output candidates ticket number and seat number examination, separated by a space.

Sample input:
. 4
3,310,120,150,912,233. 4 2
3310120150912119. 4. 1
3,310,120,150,912,126. 1. 3
3310120150912002 2. 3
2
. 3. 4

Output Sample:
3310120150912002 2
3310120150912119 1

Problem-solving ideas: The number and the ticket examination number to fight with the map stored, according to the test machine number and the test number and ticket number read out, the final output can be

#include<iostream>
#include<cstdio>
#include<string>
#include<map>
using namespace std;
int k[1000];
string n[1000];
int main(){
	int num = 0,tryNum=0,seatNum=0,num2=0;
	map<int,string> stuMap;
	string line;
	cin >> num;
	for (int i = 0; i < num; i++){
		cin>>line>>tryNum>>seatNum;
		stuMap[tryNum] = line+","+to_string(seatNum);
	}
	cin >> num2;
	for (int i = 0; i < num2; i++){
		cin >> k[i];
		n[i]= stuMap[k[i]];
	}
	for (int i = 0; i < num2; i++){
		int index = n[i].find(",");
		string x = n[i].substr(0, index);
		string y = n[i].substr(index + 1);
		cout << x << " " << y<<endl;
	}
	return 0;
}
发布了46 篇原创文章 · 获赞 0 · 访问量 579

Guess you like

Origin blog.csdn.net/qq_23079139/article/details/104102402