有两那个下标错了,改好了。
#include<iostream>
using namespace std;
struct student {
int intime;
int plantime;
int time;
};
int main() {
student a[1000];
int n[1000];
int sumn = 0;
int T;
cout << "Please enter the number of data groups T: ";
cin >> T;
for (int i = 0; i < T; i++) {
cout << "For group " << i << ", please enter the number of students n: ";
int sumtime = 0;
cin >> n[i];
for (int j = 0; j < n[i]; j++) {
cout << "For group " << i << ", steudent " << j << ", please enter the arriving time and planned leaving time: ";
cin >> a[sumn + j].intime;
cin >> a[sumn + j].plantime;
if (a[sumn + j].intime <= sumtime)
sumtime += 1;
else
sumtime = a[sumn + j].intime ;
if (a[sumn + j].plantime < sumtime) {
a[sumn + j].time= 0;
sumtime -= 1;
}
else
a[sumn + j].time = sumtime; }
sumn += n[i];
}
cout << "Following are the " << T << " groups of students' service times: " << endl;
sumn = 0;
for (int i = 0; i < T; i++) {
for (int j = 0; j < n[i]; ++j) {
cout << a[sumn + j].time << " ";
}
cout << endl;
sumn += n[i];
}
return 0;
}
// Output
Please enter the number of data groups T: 2
For group 0, please enter the number of students n: 2
For group 0, steudent 0, please enter the arriving time and planned leaving time: 1 3
For group 0, steudent 1, please enter the arriving time and planned leaving time: 1 4
For group 1, please enter the number of students n: 3
For group 1, steudent 0, please enter the arriving time and planned leaving time: 1 5
For group 1, steudent 1, please enter the arriving time and planned leaving time: 1 1
For group 1, steudent 2, please enter the arriving time and planned leaving time: 2 3
Following are the 2 groups of students' service times:
1 2
1 0 2