Revisions
-
iissnan revised this gist
Jan 13, 2014 . 1 changed file with 8 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,7 +30,7 @@ void main() else if(strcmp(sClass[i], sClass[j]) < 0) { // i < j, swap class. s(i, j); } else { @@ -39,7 +39,7 @@ void main() // id: i >= j, do not swap. } else { // id: i < j, swap. s(i,j); } } } @@ -50,14 +50,14 @@ void main() printf("%s %s %s\n", sClass[i], sID[i], sName[i]); } } void s(int i, int j) { char sTemp[LENGTH]; strcpy(sTemp, sClass[i]); strcpy(sClass[i], sClass[j]); strcpy(sClass[j], sTemp); strcpy(sTemp, sID[i]); strcpy(sID[i], sID[j]); strcpy(sID[j], sTemp); -
iissnan revised this gist
Jan 13, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -52,7 +52,7 @@ void main() } void s(int i, int j, int type) { char sTemp[LENGTH]; if (type == 0) { //swap class strcpy(sTemp, sClass[i]); strcpy(sClass[i], sClass[j]); -
iissnan revised this gist
Jan 13, 2014 . 1 changed file with 23 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,21 +25,22 @@ void main() { if(strcmp(sClass[i], sClass[j]) > 0) { // i > j, do not swap. } else if(strcmp(sClass[i], sClass[j]) < 0) { // i < j, swap class. s(i, j, 0); } else { // i = j, compare id. if(strcmp(sID[i], sID[j]) >= 0) { // id: i >= j, do not swap. } else { // id: i < j, swap. s(i,j, 1); } } } } @@ -49,13 +50,19 @@ void main() printf("%s %s %s\n", sClass[i], sID[i], sName[i]); } } void s(int i, int j, int type) { char sTemp; if (type == 0) { //swap class strcpy(sTemp, sClass[i]); strcpy(sClass[i], sClass[j]); strcpy(sClass[j], sTemp); } strcpy(sTemp, sID[i]); strcpy(sID[i], sID[j]); strcpy(sID[j], sTemp); strcpy(sTemp, sName[i]); strcpy(sName[i], sName[j]); strcpy(sName[j], sTemp); } -
iissnan revised this gist
Jan 13, 2014 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,17 +29,17 @@ void main() strcpy(sClass[i], sClass[j]); //sClass[i] = sClass[j]; strcpy(sClass[j], sTemp); //sClass[j] = sTemp; if(strcmp(sID[i], sID[j]) > 0) s(i,j); } else if(strcmp(sClass[i], sClass[j]) < 0) { if(strcmp(sID[i], sID[j]) > 0) s(i,j); } else { if(strcmp(sID[i], sID[j]) > 0) s(i,j); } } } -
iissnan revised this gist
Jan 13, 2014 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,10 +5,12 @@ #include <string.h> #define N 5 #define LENGTH 10 char sName[N][LENGTH], sID[N][LENGTH], sClass[N][LENGTH]; void s(); void main() { char sTemp; int i, j; printf("逐行输入学生的班级,学号和姓名:"); @@ -47,11 +49,9 @@ void main() printf("%s %s %s\n", sClass[i], sID[i], sName[i]); } } void s(int i, int j) { char sTemp; strcpy(sTemp, sID[i]); //sTemp = sID[i]; strcpy(sID[i], sID[j]); //sID[i] = sID[j]; strcpy(sID[j], sTemp); //sID[j] = sTemp; -
novnan revised this gist
Jan 13, 2014 . 1 changed file with 31 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,8 +3,9 @@ #include <stdio.h> #include <string.h> #define N 5 #define LENGTH 10 void s(); void main() { char sName[N][LENGTH], sID[N][LENGTH], sClass[N][LENGTH]; @@ -20,17 +21,23 @@ void main() { for(j = i + 1; j < N; j++) { if(strcmp(sClass[i], sClass[j]) > 0) { strcpy(sTemp, sClass[i]); //sTemp = sClass[i]; strcpy(sClass[i], sClass[j]); //sClass[i] = sClass[j]; strcpy(sClass[j], sTemp); //sClass[j] = sTemp; if(strcmp(sID[i], sID[j]) > 0) s(sID[i], sID[j], sName[i], sName[j]); } else if(strcmp(sClass[i], sClass[j]) < 0) { if(strcmp(sID[i], sID[j]) > 0) s(sID[i], sID[j], sName[i], sName[j]); } else { if(strcmp(sID[i], sID[j]) > 0) s(sID[i], sID[j], sName[i], sName[j]); } } } @@ -39,4 +46,16 @@ void main() { printf("%s %s %s\n", sClass[i], sID[i], sName[i]); } } void s() { char sName[N][LENGTH], sID[N][LENGTH], sClass[N][LENGTH]; char sTemp; int i, j; strcpy(sTemp, sID[i]); //sTemp = sID[i]; strcpy(sID[i], sID[j]); //sID[i] = sID[j]; strcpy(sID[j], sTemp); //sID[j] = sTemp; strcpy(sTemp, sName[i]); //sTemp = sName[i]; strcpy(sName[i], sName[j]); //sName[i] = sName[j]; strcpy(sName[j], sTemp); //sName[j] = sTemp; } -
novnan created this gist
Jan 13, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ // 有近百名学生选修了某们课程,他们来源不同的专业班级,按班级,学号顺序打印学生的班级名称,学号和姓名。 #include <stdio.h> #include <string.h> #define N 100 #define LENGTH 10 void main() { char sName[N][LENGTH], sID[N][LENGTH], sClass[N][LENGTH]; char sTemp; int i, j; printf("逐行输入学生的班级,学号和姓名:"); for(i = 0; i < N; i++) { scanf("%s%s%s", sClass[i], sID[i], sName[i]); } // 冒泡法,排序的依据是班级和学号,即优先排班级,班级一样再按学号排序 for(i = 0; i < N; i++) { for(j = i + 1; j < N; j++) { if((sClass[i] > sClass[j]) && (sID[i] > sID[j])) { sTemp = sClass[i]; sClass[i] = sClass[j]; sClass[j] = sTemp; sTemp = sID[i]; sID[i] = sID[j]; sID[j] = sTemp; strcpy(sTemp, sName[i]); strcpy(sName[i], sName[j]); strcpy(sName[j], sTemp); } } } printf("排序后的班级,学号和姓名:\n"); for(i = 0; i < N; i++) { printf("%s %s %s\n", sClass[i], sID[i], sName[i]); } }