很恶心啊, 卡输入输出 ,不能用cin cout 关掉了同步也不行,估计是pta不能关掉同步
然后手动转换一下就行, 用了 const char *t = (string).c_str(); 用这个就可以很快的string 变char 不然在写排序算法的时候,判断是比较麻烦的
Excel可以对一组纪录按任意指定列排序。现请编写程序实现类似功能。
输入格式:
输入的第一行包含两个正整数N(≤) 和C,其中N是纪录的条数,C是指定排序的列号。之后有 N行,每行包含一条学生纪录。每条学生纪录由学号(6位数字,保证没有重复的学号)、姓名(不超过8位且不包含空格的字符串)、成绩([0, 100]内的整数)组成,相邻属性用1个空格隔开。
输出格式:
在N行中输出按要求排序后的结果,即:当C=1时,按学号递增排序;当C=2时,按姓名的非递减字典序排序;当C=3时,按成绩的非递减排序。当若干学生具有相同姓名或者相同成绩时,则按他们的学号递增排序。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <math.h>
#include <stack>
#include <utility>
#include <string>
#include <sstream>
#include <cstdlib>
#include <set>
#define LL long long
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 10;
int dir[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
struct Student
{
string name;
string id;
int sc;
Student(){}
Student(string n,string ID,int num)
{
name = n;
id = ID;
sc = num;
}
}pt[maxn];
bool cmp1(const Student a,const Student b)
{
return a.id < b.id;
}
bool cmp2(const Student a,const Student b)
{
if(a.name != b.name)
return a.name < b.name;
else
return a.id < b.id;
}
bool cmp3(const Student a,const Student b)
{
if(a.sc != b.sc)
return a.sc < b.sc;
else
return a.id < b.id;
}
int n,c;
int main()
{
scanf("%d %d",&n,&c);
char Name[30];
char ID[30];
int num;
for(int i = 0;i < n;i++)
{
scanf("%s %s %d",ID,Name,&num);
string N = Name;
string I = ID;
pt[i].id = I;
pt[i].name = N;
pt[i].sc = num;
}
if(c == 1)
sort(pt,pt+n,cmp1);
else if(c == 2)
sort(pt,pt+n,cmp2);
else
sort(pt,pt+n,cmp3);
for(int i = 0;i < n;i++)
{
const char *I = pt[i].id.c_str();
const char *N = pt[i].name.c_str();
printf("%s %s %d\n",I,N,pt[i].sc);
}
return 0;
}