1 条题解
-
0
C++ :
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; struct USER { int score; int ac; char name[16]; char name1[16]; char suoxie[16]; } user[100]; bool cmp(USER a, USER b) { if (a.score == b.score) { if (a.ac == b.ac) { if (!strcmp(a.suoxie, b.suoxie)) return strcmp(a.name1, b.name1) < 0 ? 1 : 0; return strcmp(a.suoxie, b.suoxie) < 0 ? 1 : 0; } return a.ac > b.ac; } return a.score > b.score; } int main() { int n, a, b, i, k, c = 0; char s[16], *p; while (scanf("%d", &n) != EOF, n) { for (i = 0; i < n; i++) { scanf("%d%d%*c", &user[i].score, &user[i].ac); gets(s); strcpy(user[i].name, s); strcpy(user[i].name1, "\0"); p = strtok(s, " "); k = 0; while (p) { strcat(user[i].name1, p); user[i].suoxie[k++] = *p; p = strtok(NULL," "); } user[i].suoxie[k] = '\0'; } sort(user, user + n, cmp); if (c++) puts(""); for (i = 0; i < n; i++) printf("%d %d %s\n", user[i].score, user[i].ac, user[i].name); } return 0; }
Pascal :
var a,d,e:array[1..100]of string[40];b,c:array[1..100]of integer;x,m:string[50];n,i,j,y,t:integer; begin readln(n); while n<>0 do begin t:=t+1; for i:=1 to n do begin readln(a[i]);d[i]:=a[i]; val(copy(d[i],1,pos(' ',d[i])-1),b[i],y); delete(d[i],1,pos(' ',d[i])); end; for i:=1 to n do for j:=1 to n-i do if b[j]<b[j+1] then begin y:=b[j];b[j]:=b[j+1];b[j+1]:=y; x:=a[j];a[j]:=a[j+1];a[j+1]:=x; x:=d[j];d[j]:=d[j+1];d[j+1]:=x; end; for i:=1 to n do begin val(copy(d[i],1,pos(' ',d[i])-1),c[i],y); delete(d[i],1,pos(' ',d[i])) end; for i:=1 to n do for j:=1 to n-i do if (b[j]=b[j+1])and(c[j]<c[j+1]) then begin y:=c[j];c[j]:=c[j+1];c[j+1]:=y; y:=b[j];b[j]:=b[j+1];b[j+1]:=y; x:=a[j];a[j]:=a[j+1];a[j+1]:=x; x:=d[j];d[j]:=d[j+1];d[j+1]:=x; end; for i:=1 to n do begin e[i]:=copy(d[i],1,1)+copy(d[i],pos(' ',d[i])+1,1); end; for i:=1 to n do for j:=1 to n-i do if (b[j]=b[j+1])and(c[j]=c[j+1])and(e[j]>e[j+1]) then begin x:=e[j];e[j]:=e[j+1];e[j+1]:=x; y:=c[j];c[j]:=c[j+1];c[j+1]:=y; y:=b[j];b[j]:=b[j+1];b[j+1]:=y; x:=a[j];a[j]:=a[j+1];a[j+1]:=x; x:=d[j];d[j]:=d[j+1];d[j+1]:=x; end; for i:=1 to n do repeat delete(d[i],pos(' ',d[i]),1) until pos(' ',d[i])=0; for i:=1 to n do for j:=1 to n-i do if (b[j]=b[j+1])and(c[j]=c[j+1])and(e[j]=e[j+1])and(d[j]>d[j+1]) then begin x:=d[j];d[j]:=d[j+1];d[j+1]:=x; x:=e[j];e[j]:=e[j+1];e[j+1]:=x; y:=c[j];c[j]:=c[j+1];c[j+1]:=y; y:=b[j];b[j]:=b[j+1];b[j+1]:=y; x:=a[j];a[j]:=a[j+1];a[j+1]:=x; end; if t<>1 then writeln; for i:=1 to n do writeln(a[i]); readln(n) end end.
Java :
import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Scanner; public class Main { private static ArrayList<Person> persons=new ArrayList<>(); public static String suoxie; public static String name; public static String name1; public static void main(String[] args) { Scanner scanner=new Scanner(System.in); String totalsString=scanner.nextLine(); int total=Integer.parseInt(totalsString); while(total!=0) { while(total--!=0) { suoxie=""; name=""; name1=""; String tempString=scanner.nextLine(); String buffer[]=tempString.split(" "); for(int i=2;i<buffer.length;i++) { suoxie+=buffer[i].charAt(0); name+=buffer[i]; name1+=" "+buffer[i]; } Person person=new Person(Integer.parseInt(buffer[0]), Integer.parseInt(buffer[1]), suoxie, name,name1); persons.add(person); } sort(); printPerson(persons); persons.clear(); total=Integer.parseInt(scanner.nextLine()); } } private static void printPerson(ArrayList<Person> persons) { for(int j=0;j<persons.size();j++) { Person person=persons.get(j); System.out.println(person.score+" "+person.acNum+person.name1); } System.out.println(); } public static void sort(){ Collections.sort(persons, new Comparator<Person>() { @Override public int compare(Person o1, Person o2) { if(o1.score==o2.score) { if(o1.acNum==o2.acNum) { if(o1.suoxie.equals(o2.suoxie)) { return o1.name.compareTo(o2.name); } return o1.suoxie.compareTo(o2.suoxie); } return o1.acNum<o2.acNum?1:-1; } return o1.score<o2.score?1:-1; } }); } } class Person{ public int score; public int acNum; public String suoxie; public String name; public String name1; public Person(int score, int acNum, String suoxie, String name, String name1) { super(); this.score = score; this.acNum = acNum; this.suoxie = suoxie; this.name = name; this.name1 = name1; } }
- 1
信息
- ID
- 2257
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者