1025 PAT Ranking (25 分)
Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. Now it is your job to write a program to correctly merge all the ranklists and generate the final rank.
Input Specification:
Each input file contains one test case. For each case, the first line contains a positive number N (≤100), the number of test locations. Then N ranklists follow, each starts with a line containing a positive integer K (≤300), the number of testees, and then K lines containing the registration number (a 13-digit number) and the total score of each testee. All the numbers in a line are separated by a space.
Output Specification:
For each test case, first print in one line the total number of testees. Then print the final ranklist in the following format:
registration_number final_rank location_number local_rank
The locations are numbered from 1 to N. The output must be sorted in nondecreasing order of the final ranks. The testees with the same score must have the same rank, and the output must be sorted in nondecreasing order of their registration numbers.
Sample Input:
2
5
1234567890001 95
1234567890005 100
1234567890003 95
1234567890002 77
1234567890004 85
4
1234567890013 65
1234567890011 25
1234567890014 100
1234567890012 85
Sample Output:
9
1234567890005 1 1 1
1234567890014 1 2 1
1234567890001 3 1 2
1234567890003 3 1 2
1234567890004 5 1 4
1234567890012 5 2 2
1234567890002 7 1 5
1234567890013 8 2 3
1234567890011 9 2 4
题目大意:模拟一下PAT考试的排名方法,就是每个学生考完都应该有,注册号,分数,场次,该场名次,总名次。现在只告诉你每个学生的注册号和分数,要去完善这些属性,并按顺序输出。
解题思路:水题,排排序就ok了。
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<time.h>
#include<math.h>
#include<set>
#include<map>
using namespace std;
struct stu {
string id;
int frank;
int locnum;
int locrank;
int score;
};
bool Cmp(stu a, stu b) {
if (a.score > b.score)return true;
else if (a.score == b.score) return a.id < b.id;
else
return false;
}
vector<stu> list;
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int m;
cin >> m;
stu cur[305];
for (int j = 0; j < m; j++) {
cin >> cur[j].id >> cur[j].score;
cur[j].locnum = i + 1;
}
sort(cur, cur + m,Cmp);
int index = 1;
cur[0].locrank = 1;
list.push_back(cur[0]);
for (int q = 1; q < m; q++) {
if (cur[q].score < cur[q - 1].score)
index = q + 1;
cur[q].locrank = index;
list.push_back(cur[q]);
}
}
sort(list.begin(), list.end(), Cmp);
int index = 1;
list[0].frank = 1;
for (int i = 1; i < list.size(); i++) {
if (list[i].score < list[i - 1].score)
index = i + 1;
list[i].frank = index;
}
cout << list.size() << endl;
for (int i = 0; i < list.size(); i++) {
cout << list[i].id << " " << list[i].frank <<" "<<list[i].locnum<<" "<< list[i].locrank << endl;
}
return 0;
}
1027 Colors in Mars (20 分)
People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits are for Red
, the middle 2 digits for Green
, and the last 2 digits for Blue
. The only difference is that they use radix 13 (0-9 and A-C) instead of 16. Now given a color in three decimal numbers (each between 0 and 168), you are supposed to output their Mars RGB values.
Input Specification:
Each input file contains one test case which occupies a line containing the three decimal color values.
Output Specification:
For each test case you should output the Mars RGB value in the following format: first output #
, then followed by a 6-digit number where all the English characters must be upper-cased. If a single color is only 1-digit long, you must print a 0
to its left.
Sample Input:
15 43 71
Sample Output:
#123456
题目大意:给你三原色的三个参数,地球上是16进制转换串要你转换成13进制转换串。输出一下。
解题思路:水题,就进制转换一下就好了,输出相应数。把转换出0位1位特殊处理一下。
代码如下
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<time.h>
#include<math.h>
#include<set>
#include<map>
using namespace std;
vector<char> trans(int a) {
vector<char> tmp;
while (a!=0) {
char cur;
if (a % 13 >= 10)cur = ((a % 13) - 10 + 'A');
else
cur = ((a % 13) + '0');
tmp.push_back(cur);
a = a / 13;
}
reverse(tmp.begin(),tmp.end());
return tmp;
}
void Printres(int a,int b,int c) {
cout << "#";
if (trans(a).size() == 1)
cout << "0" << trans(a)[0];
else if (trans(a).size() == 0)
cout << "00";
else
cout << trans(a)[0] << trans(a)[1];
if (trans(b).size() == 1)
cout << "0" << trans(b)[0];
else if (trans(b).size() == 0)
cout << "00";
else
cout << trans(b)[0] << trans(b)[1];
if (trans(c).size() == 1)
cout << "0" << trans(c)[0] << endl;
else if (trans(c).size() == 0)
cout << "00" << endl;
else
cout << trans(c)[0] << trans(c)[1] << endl;
}
int main()
{
int a, b, c;
cin >> a >> b >> c;
trans(a);
Printres(a, b, c);
return 0;
}