简单的食堂排队问题,例子都成功实现,为什么还是过不了,我疏漏了哪里?

#include<iostream>
using namespace std;

struct student {
	int intime;
	int plantime;
	int time;
};
	
int main() {
	student a[1000];
	int i, j, k;
	int T, n;
	cin >> T;
	for (i = 0; i < T; i++) {
		int sumtime;
		cin >> n;
		cin >> a[0].intime;
		cin >> a[0].plantime;
		sumtime = a[0].intime;
		a[0].time = sumtime;
		for (j = 1; j < n; j++) {
			cin >> a[j].intime;
			cin >> a[j].plantime;
			if (a[j].intime <= sumtime)sumtime += 1;
			else sumtime = a[j].intime ;
			if (a[j].plantime < sumtime) {
				a[j].time= 0;
				sumtime -= 1;
			}
			else a[j].time = sumtime;
		}
		for (k = 0; k < n; k++) {
			if (k == 0)cout << a[k].time;
			else cout << ' ' << a[k].time;
		}
		
	}
 
}

 

有两那个下标错了,改好了。

#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

 

请问你做的是啥,面试的题库吗

 

n 应该试数组,记录每组学生数。我修改了你得程序并且运行了、你看看。

 

#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[j].time= 0;
				sumtime -= 1;
			}
			else 
			    a[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: 3                                                                                                                                         
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 2                                                                                               
For group 0, steudent 1, please enter the arriving time and planned leaving time: 2 3                                                                                               
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 2                                                                                               
For group 1, steudent 1, please enter the arriving time and planned leaving time: 2 3                                                                                               
For group 1, steudent 2, please enter the arriving time and planned leaving time: 3 4                                                                                               
For group 2, please enter the number of students n: 4                                                                                                                               
For group 2, steudent 0, please enter the arriving time and planned leaving time: 1 2                                                                                               
For group 2, steudent 1, please enter the arriving time and planned leaving time: 2 3                                                                                               
For group 2, steudent 2, please enter the arriving time and planned leaving time: 3 2                                                                                               
For group 2, steudent 3, please enter the arriving time and planned leaving time: 3 4                                                                                               
Following are the 3 groups of students' service times:                                                                                                                              
1 2                                                                                                                                                                                 
0 3 0                                                                                                                                                                               
0 0 0 0