PAT:1028. List Sorting (25) AC

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct Student
{
  char ID[10];
  char name[10];
  int gread;
}STU[100010];

bool cmp1(Student a,Student b)
{
  return strcmp(a.ID,b.ID)<0;
}

bool cmp2(Student a,Student b)
{
  if(strcmp(a.name,b.name)!=0)
    return strcmp(a.name,b.name)<0;
  else
    return strcmp(a.ID,b.ID)<0;
}

bool cmp3(Student a,Student b)
{
  if(a.gread!=b.gread)
    return a.gread<b.gread;
  else
    return strcmp(a.ID,b.ID)<0;
}

int main()
{
  int n,accord;
  scanf("%d%d",&n,&accord);
  for(int i=0 ; i<n ; ++i)
  {
    scanf("%s %s %d",&STU[i].ID, &STU[i].name, &STU[i].gread);
  }
  if(accord==1)
    sort(STU,STU+n,cmp1);
  if(accord==2)
    sort(STU,STU+n,cmp2);
  if(accord==3)
    sort(STU,STU+n,cmp3);
  for(int i=0 ; i<n ; ++i)
    printf("%s %s %d\n",STU[i].ID,STU[i].name,STU[i].gread);
  return 0;
}
时间: 2024-08-08 22:09:15

PAT:1028. List Sorting (25) AC的相关文章

PAT 甲级 1028 List Sorting (25 分)(排序,简单题)

1028 List Sorting (25 分)   Excel can sort records according to any column. Now you are supposed to imitate this function. Input Specification: Each input file contains one test case. For each case, the first line contains two integers N (≤) and C, wh

PAT Advanced 1028 List Sorting (25分)

Excel can sort records according to any column. Now you are supposed to imitate this function. Input Specification: Each input file contains one test case. For each case, the first line contains two integers N (≤) and C, where N is the number of reco

PAT甲级 1028 List Sorting (25分)(cin cout 超时问题)

注意: 用scanf 和printf 进行输入输出 否则超时 cin,cout速度慢的原因就是它会将数据先读入缓冲区,然后再读入,所以与scanf的直接读入会有点时间差距. 1.换成scanf 和 printf输入输出 2.加一条语句 ios::sync_with_stdio(false); 题目代码: 1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <algori

PAT:1059. Prime Factors (25) AC

#include<stdio.h> #include<math.h> #include<string.h> #include<algorithm> using namespace std; const int MAX=100010; //int型素数一定在这个范围内 int PrimeArr[MAX]; //素数表 int cnt=0; //素数表中素数个数 int x,x2; //输入的数字,x2是x的开平方数,x的因子只有从2到根号x+1 struct

PAT:1071. Speech Patterns (25) AC

#include<ctype.h> #include<iostream> #include<map> #include<string> using namespace std; bool check(char a) //判断是否为有效字符 { if(isdigit(a) || isalpha(a)) return true; return false; } int main() { map<string,int> count; //单词与次数的映

PAT:1028. 人口普查(20) AC

#include<stdio.h> #include<stdlib.h> #include<string.h> #include<algorithm> using namespace std; struct STU { char mname[10]; int y,m,d; }tmp,old,young,left,right; void init() { old.y=right.y=2014; young.y=left.y=1814; old.m=right.

PAT:1020. Tree Traversals (25) AC

#include<stdio.h> #include<stdlib.h> #include<queue> using namespace std; int POST[32]; //存放后序遍历 int IN[32]; //存放中序遍历 int n; //节点数 struct node { int data; node* l; node* r; }; node* creat(int postL,int postR,int inL,int inR) { if(postL&g

PAT:1063. Set Similarity (25) AC

#include<stdio.h> #include<set> using namespace std; set<int> str[51]; //最大51个集合 void compare(int s1,int s2) { int different=str[s1].size(),same=0; //初始化并集元素为s1元素个数,交集元素0个 for(set<int>::iterator it=str[s2].begin() ; it!=str[s2].end

PAT:1015. 德才论 (25) AC

#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; struct Student { char mID[10]; int de,cai,sum; int tag; //标明是第几类:1德才都们组,2德胜才,3 }STU[100010]; bool cmp(Student a,Student b) //[warning]不能写STU { if(a.tag!=b.tag)