1 条题解
-
0
C :
#include<stdio.h> #include<stdlib.h> #include<string.h> int main() { char c[5][20]={'0'}; int a[5][2]; char temp[20]; int temp1; for(int i=0;i<4;i++) { scanf("%s",&c[i]); scanf("%d%d",&a[i][0],&a[i][1]); } for(int i=0;i<3;i++) for(int j=1;j<4-i;j++) if(a[j-1][1]<a[j][1]) { strcpy(temp,c[j-1]); strcpy(c[j-1],c[j]); strcpy(c[j],temp); temp1=a[j-1][0]; a[j-1][0]=a[j][0]; a[j][0]=temp1; temp1=a[j-1][1]; a[j-1][1]=a[j][1]; a[j][1]=temp1; } for(int i=0;i<4;i++) { printf("%s ",c[i]); printf("%d %d\n",a[i][0],a[i][1]); } //system("pause"); return 0; }
C++ :
#include<iostream> #include<fstream> #include<string> using namespace std; struct student { string name; int age; int score; }; int main() { student st[4]; student s; student t; int i=0; for(i=0; i<4; i++) { cin>>st[i].name>>st[i].age>>st[i].score; } for(i=0; i<4; i++) for(int j=i+1; j<4; j++) if(st[i].score<st[j].score) { t=st[i]; st[i]=st[j]; st[j]=t; } for(i=0; i<4; i++) cout<<st[i].name<<" "<<st[i].age<<" "<<st[i].score<<endl; return 0; }
Pascal :
var a:array[1..100000] of string; b,c:array[1..100000] of longint; str:string; i,k:longint; procedure qsort(l,r:longint); var i,j,t,mid1,mid2:longint; s:string; begin i:=l; j:=r; mid1:=b[(i+j) div 2]; mid2:=c[(i+j) div 2]; repeat while (c[i]>mid2) or (c[i]=mid2) and (b[i]<mid1) do inc(i); while (c[j]<mid2) or (c[j]=mid2) and (b[j]>mid1) do dec(j); if i<=j then begin s:=a[i]; a[i]:=a[j]; a[j]:=s; t:=b[i]; b[i]:=b[j]; b[j]:=t; t:=c[i]; c[i]:=c[j]; c[j]:=t; inc(i); dec(j); end; until i>j; if l<j then qsort(l,j); if i<r then qsort(i,r); end; begin for i:=1 to 4 do begin readln(str); a[i]:=copy(str,1,pos(' ',str)-1); delete(str,1,pos(' ',str)); val(copy(str,1,pos(' ',str)-1),b[i],k); delete(str,1,pos(' ',str)); val(str,c[i],k); end; qsort(1,4); for i:=1 to 4 do writeln(a[i],' ',b[i],' ',c[i]); end.
Java :
import java.text.DecimalFormat; import java.util.Arrays; import java.util.Scanner; public class Main { private static Scanner s = new Scanner(System.in) ; private static DecimalFormat df = new DecimalFormat("0.0") ; public static void main(String[] args) { A a[] = new A[4] ; for (int i = 0; i < 4; i++) { String name = s.next() ; int age = s.nextInt() ; int score = s.nextInt() ; a[i] = new A(name, age, score) ; } Arrays.sort(a) ; for (int i = a.length-1; i>=0; i--) { System.out.println(a[i].name+" "+a[i].age+" "+a[i].score); } } } class A implements Comparable{ String name ; int age ; int score ; public A(String name, int age, int score) { super(); this.name = name; this.age = age; this.score = score; } @Override public int compareTo(Object o) { A a = (A) o ; if(a.score<this.score){ return 1 ; }else if(a.score==this.score){ return 0; }else return -1 ; } }
- 1
信息
- ID
- 537
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者