Home > Back-end >  Cattle from clang 3.3: why I can't complete structure after a bubble sort an array output
Cattle from clang 3.3: why I can't complete structure after a bubble sort an array output

Time:09-23

Topic is to input the number of students n first, and then sort input mode flag (0 represents descending, 1 (ascending), and then input n student's name and grade, and then sorted by sorting mode and the output, demand stable sorting algorithms,
Question: my code on the local compiler can run normal compilation, but the cattle from clang++ 3.3 compiled always can't through the test cases (test case attached below), can only output sorted before 11 data, the data behind the run where go to?
See others insert algorithm, and the time complexity and I didn't poor, but can be normal, please answer, thank you!
My code:
 # include & lt; Iostream> 
#include
using namespace std;
Struct Student {
Public:
String name;
Int score;
};
Void changestu (Student & amp; A, Student & amp; B) {
Student TMP=a;
a=b;
B=TMP;
}
Int main ()
{
Student stu [1000].
Int n=0;
Int flag=0;
While (cin> N> Flag) {
for(int i=0; icin> Stu [I] name> Stu [I] score;
If (flag==0) {
For (int p=0; pFor (int q=p + 1; QIf (stu [p]. Score<[q]. Stu score) {
Changestu (stu [p], stu [q]);
}
}
}
} else {
For (int p=0; pFor (int q=p + 1; QIf (stu [p]. Score> [q]. Stu score) {
Changestu (stu [p], stu [q]);
}
}
}
}
For (int r=0; rCout}
}

Test case:
 
28
1
QHSQ 15
Ozslg 79
NCTTMTSPHB 71
A 39
Eeiuyzsj 34
Nmlrokx 21
Pjizylo 90
Ec 45
12 f
Sh 31
FM 25
Ptprphubqk 29
Wxdiwv 0
Uhlcpjtxad 60
W 20
Zwktbpun 70
Efzfkf 69
V 31
RSNRGTL 73
Lhdo 76
Wt 56
MCDWD 14
Ydrnoyd 37
GMLFDS 76
Zx 1
DQX 98
Gz 90
KVBZRWRRJJ 13

Cattle attracts my test cases run results:
 
Wxdiwv 0
Zx 1
12 f
KVBZRWRRJJ 13
MCDWD 14
QHSQ 15
W 20
Nmlrokx 21
FM 25
Ptprphubqk 29
V 31
  • Related