parent
b3e7a1ee4d
commit
ed2f90beef
@ -0,0 +1,102 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
int main(){
|
||||
int CORRECT(float m[][4],char m1[][6],char m2[][10],int r);
|
||||
int SORT(float m[][4],char m1[][6],char m2[][10],int r,int t);
|
||||
int i,j,signal;
|
||||
float message[3][4]={{11,99.5,88.5,89.5},{12,77.9,56.5,87.5},{11,92.5,99.0,60.5}};
|
||||
char message_number[3][6]={"10001","10002","10003"};
|
||||
char message_name[3][10]={"Zhang","Yang","Liang"};
|
||||
signal=CORRECT(message,message_number,message_name,3);
|
||||
signal=SORT(message,message_number,message_name,3,signal);
|
||||
for(i=0;i<3;i++){
|
||||
if(i>0&&message[i-1][0]==message[i][0]){
|
||||
printf(" ");
|
||||
}
|
||||
else
|
||||
printf("%d ",(int)message[i][0]);
|
||||
printf("%s ",message_number[i]);
|
||||
printf("%s ",message_name[i]);
|
||||
for(j=1;j<=2;j++){
|
||||
printf("%.1f ",message[i][j]);
|
||||
}
|
||||
if(i==signal){
|
||||
printf("%.1f modified\n",message[i][3]);
|
||||
}
|
||||
else{
|
||||
printf("%.1f\n",message[i][3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
int CORRECT(float m[][4],char m1[][6],char m2[][10],int r){
|
||||
int i,j,signal,word=0;
|
||||
char number[6];
|
||||
scanf("%5s",number);
|
||||
number[6]='\0';
|
||||
for(i=0;i<r&&word==0;i++){
|
||||
if(strcmp(number,m1[i])==0){
|
||||
scanf("%f",(*(m+i)+0));
|
||||
scanf("%s",m2[i]);
|
||||
for(j=1;j<=3;j++){
|
||||
scanf("%f",(*(m+i)+j));
|
||||
}
|
||||
signal=i;
|
||||
word=1;
|
||||
}
|
||||
}
|
||||
if(word==0)
|
||||
return(r);
|
||||
else
|
||||
return(signal);
|
||||
}
|
||||
int SORT(float m[][4],char m1[][6],char m2[][10],int r,int t){
|
||||
void SWAPNUMBER(float a[],float b[],int c);
|
||||
void SWAPSTRING(char a[],char b[]);
|
||||
int i,j,s;
|
||||
for(i=1;i<r;i++){
|
||||
for(j=0;j<r-i;j++){
|
||||
if(*(*(m+j)+0)>*(*(m+j+1)+0)){
|
||||
SWAPNUMBER(m[j],m[j+1],4);
|
||||
SWAPSTRING(m1[j],m1[j+1]);
|
||||
SWAPSTRING(m2[j],m2[j+1]);
|
||||
if(j==t)
|
||||
t++;
|
||||
}
|
||||
|
||||
else if(*(*(m+j)+0)==*(*(m+j+1)+0)){
|
||||
float totalscore1=*(*(m+j)+1)+*(*(m+j)+2)+*(*(m+j)+3);
|
||||
float totalscore2=*(*(m+j+1)+1)+*(*(m+j+1)+2)+*(*(m+j+1)+3);
|
||||
if(totalscore1<totalscore2){
|
||||
SWAPNUMBER(m[j],m[j+1],4);
|
||||
SWAPSTRING(m1[j],m1[j+1]);
|
||||
SWAPSTRING(m2[j],m2[j+1]);
|
||||
if(j==t)
|
||||
t++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return(t);
|
||||
}
|
||||
void SWAPNUMBER(float a[],float b[],int c){
|
||||
float t[c];
|
||||
int s;
|
||||
for(s=0;s<c;s++){
|
||||
*(t+s)=*(a+s);
|
||||
*(a+s)=*(b+s);
|
||||
*(b+s)=*(t+s);
|
||||
}
|
||||
}
|
||||
void SWAPSTRING(char a[],char b[]){
|
||||
int l1=strlen(a),l2=strlen(b);
|
||||
char s[20];
|
||||
strcpy(s,a);
|
||||
strcpy(a,b);
|
||||
strcpy(b,s);
|
||||
if(l1>l2){
|
||||
a[l2]='\0';
|
||||
}
|
||||
else if(l1<l2){
|
||||
b[l1]='\0';
|
||||
}
|
||||
}
|
Loading…
Reference in new issue