求助!结构体的变量默认不为0
查看原帖
求助!结构体的变量默认不为0
483691
TCEH920106840230楼主2021/3/8 23:53

using namespace std;
struct person{
	int song,shou,sr,zl;
	string rm,songchu[11];
	
};
int main(){
	int n;
	cin>>n;
	person people[11];
	string mmp[11];
//	string rm[n];
	for(int x=0;x<n;x++){
		cin>>people[x].rm;
	//	people[x].shou=0;这里必须将shou初始化为0否则第一个目标的shou数据为2285324这是为什么
		
	}
	for(int X=0;X<n;X++){
		cin>>mmp[X];
		for(int x=0;x<n;x++){
		if(mmp[X]==people[x].rm){
		
		
		cin>>people[x].song>>people[x].sr;
			if(people[x].sr==0){
			people[x].zl=0;
			people[x].song=0;
		}
			if(people[x].sr!=0){
			
		for(int p=0;p<people[x].sr;p++){
		
		cin>>people[x].songchu[p];}
	
		
		int sc;
		sc=int(people[x].song/people[x].sr);
		people[x].zl=people[x].song-people[x].sr*sc;
//		cout<<endl<<people[0].zl<<" "<<people[0].song<<endl;
//		rm[x].shou+=zl;
		for(int q=0;q<people[x].sr;q++){
		for(int y=0;y<n;y++){
			
			if(people[x].songchu[q]==people[y].rm){
				
				people[y].shou+=sc;
//				if(people[x].rm=="owen"){
//					cout<<"sbn"<<people[0].shou<<endl;
//					cout<<"sbsb"<<sc<<endl;
//				}
			}
			}
		}
	
	}}}
	}   
//    cout<<endl<<"sb"<<people[0].shou<<endl;
	for(int Y=0;Y<n;Y++){
	if(Y==(n-1))cout<<people[Y].rm<<" "<<people[Y].shou+people[Y].zl-people[Y].song;
	else cout<<people[Y].rm<<" "<<people[Y].shou+people[Y].zl-people[Y].song<<endl;
	}
} 
2021/3/8 23:53
加载中...