Pat(Advanced Level)Practice--1062(Talent and Virtue)
Pat1062 코드
제목 설명:
About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people's talent and virtue. According to his theory, a man being outstanding in both talent and virtue must be a'sage(성인)';being less excellent but with one's virtue outweighs talent can be calleda'nobleman(군자)';being good in neither is a "fool man(우인)"yet a fool man is better than a "small man(소인)"who prefers talent than virtue.
Now given the grades of talent and virtue of a group of people, you are supposed to rank them according to Sima Guang's theory.
Input Specification:
Each input file contains one test case. Each case first gives 3 positive integers in a line: N (<=105), the total number of people to be ranked; L (>=60), the lower bound of the qualified grades -- that is, only the ones whose grades of talent and virtue are both not below this line will be ranked; and H (<100), the higher line of qualification -- that is, those with both grades not below this line are considered as the "sages", and will be ranked in non-increasing order according to their total grades. Those with talent grades below H but virtue grades not are cosidered as the "noblemen", and are also ranked in non-increasing order according to their total grades, but they are listed after the "sages". Those with both grades below H, but with virtue not lower than talent are considered as the "fool men". They are ranked in the same way but after the "noblemen". The rest of people whose grades both pass the L line are ranked after the "fool men".
Then N lines follow, each gives the information of a person in the format: ID_Number Virtue_Grade Talent_Grade
where ID_Number is an 8-digit number, and both grades are integers in [0, 100]. All the numbers are separated by a space.
Output Specification:
The first line of output must give M (<=N), the total number of people that are actually ranked. Then M lines follow, each gives the information of a person in the same format as the input, according to the ranking rules. If there is a tie of the total grade, they must be ranked with respect to their virtue grades in non-increasing order. If there is still a tie, then output in increasing order of their ID's.
Sample Input: 14 60 80
10000001 64 90
10000002 90 60
10000011 85 80
10000003 85 80
10000004 80 85
10000005 82 77
10000006 83 76
10000007 90 78
10000008 75 79
10000009 59 90
10000010 88 45
10000012 80 100
10000013 90 99
10000014 66 60
Sample Output: 12
10000013 90 99
10000012 80 100
10000003 85 80
10000011 85 80
10000004 80 85
10000007 90 78
10000006 83 76
10000005 82 77
10000002 90 60
10000014 66 60
10000008 75 79
10000001 64 90
AC 코드:정렬 시뮬레이션 문제#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef struct People
{
int ID;
int virtue;
int talent;
int total;
}People;
vector<People> s;//sages
vector<People> n;//noble man
vector<People> f;//fool man
vector<People> o;//other people after fool man
bool cmp(const People &l,const People &r)
{
if(l.total>r.total)
return true;
else if(l.total==r.total&&l.virtue>r.virtue)
return true;
else if(l.total==r.total&&l.virtue==r.virtue&&l.ID<r.ID)
return true;
else
return false;
}
int main(int argc,char *argv[])
{
int N,L,H;
int total=0;
int i,j;
scanf("%d%d%d",&N,&L,&H);
for(i=0;i<N;i++)
{
People temp;
scanf("%d%d%d",&temp.ID,&temp.virtue,&temp.talent);
temp.total=temp.virtue+temp.talent;
if(temp.virtue>=H&&temp.talent>=H)
{
s.push_back(temp);
total++;
}
else if(temp.virtue>=H&&temp.talent<H&&temp.talent>=L)
{
n.push_back(temp);
total++;
}
else if(temp.virtue<H&&temp.virtue>=L&&temp.talent>=L&&
temp.talent<H&&temp.virtue>=temp.talent)
{
f.push_back(temp);
total++;
}
else if(temp.virtue>=L&&temp.talent>=L)
{
o.push_back(temp);
total++;
}
}
sort(s.begin(),s.end(),cmp);
sort(n.begin(),n.end(),cmp);
sort(f.begin(),f.end(),cmp);
sort(o.begin(),o.end(),cmp);
vector<People>::iterator it;
printf("%d
",total);
for(it=s.begin();it!=s.end();it++)
printf("%08d %d %d
",it->ID,it->virtue,it->talent);
for(it=n.begin();it!=n.end();it++)
printf("%08d %d %d
",it->ID,it->virtue,it->talent);
for(it=f.begin();it!=f.end();it++)
printf("%08d %d %d
",it->ID,it->virtue,it->talent);
for(it=o.begin();it!=o.end();it++)
printf("%08d %d %d
",it->ID,it->virtue,it->talent);
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
PAT 01-2
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.
ID_Number Virtue_Grade Talent_Grade
14 60 80
10000001 64 90
10000002 90 60
10000011 85 80
10000003 85 80
10000004 80 85
10000005 82 77
10000006 83 76
10000007 90 78
10000008 75 79
10000009 59 90
10000010 88 45
10000012 80 100
10000013 90 99
10000014 66 60
12
10000013 90 99
10000012 80 100
10000003 85 80
10000011 85 80
10000004 80 85
10000007 90 78
10000006 83 76
10000005 82 77
10000002 90 60
10000014 66 60
10000008 75 79
10000001 64 90
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef struct People
{
int ID;
int virtue;
int talent;
int total;
}People;
vector<People> s;//sages
vector<People> n;//noble man
vector<People> f;//fool man
vector<People> o;//other people after fool man
bool cmp(const People &l,const People &r)
{
if(l.total>r.total)
return true;
else if(l.total==r.total&&l.virtue>r.virtue)
return true;
else if(l.total==r.total&&l.virtue==r.virtue&&l.ID<r.ID)
return true;
else
return false;
}
int main(int argc,char *argv[])
{
int N,L,H;
int total=0;
int i,j;
scanf("%d%d%d",&N,&L,&H);
for(i=0;i<N;i++)
{
People temp;
scanf("%d%d%d",&temp.ID,&temp.virtue,&temp.talent);
temp.total=temp.virtue+temp.talent;
if(temp.virtue>=H&&temp.talent>=H)
{
s.push_back(temp);
total++;
}
else if(temp.virtue>=H&&temp.talent<H&&temp.talent>=L)
{
n.push_back(temp);
total++;
}
else if(temp.virtue<H&&temp.virtue>=L&&temp.talent>=L&&
temp.talent<H&&temp.virtue>=temp.talent)
{
f.push_back(temp);
total++;
}
else if(temp.virtue>=L&&temp.talent>=L)
{
o.push_back(temp);
total++;
}
}
sort(s.begin(),s.end(),cmp);
sort(n.begin(),n.end(),cmp);
sort(f.begin(),f.end(),cmp);
sort(o.begin(),o.end(),cmp);
vector<People>::iterator it;
printf("%d
",total);
for(it=s.begin();it!=s.end();it++)
printf("%08d %d %d
",it->ID,it->virtue,it->talent);
for(it=n.begin();it!=n.end();it++)
printf("%08d %d %d
",it->ID,it->virtue,it->talent);
for(it=f.begin();it!=f.end();it++)
printf("%08d %d %d
",it->ID,it->virtue,it->talent);
for(it=o.begin();it!=o.end();it++)
printf("%08d %d %d
",it->ID,it->virtue,it->talent);
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
PAT 01-2텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.