rt
问题已经排查出来了:主循环里的最后一个if判定了太多次了,导致sum太大。
AC的两个点都是全部玩/全不玩
代码:
#include <bits/stdc++.h>
using namespace std;
int n,sum=1;
//bool games[6];
bool teacher_comes = false;
bool is_there_any_student_playing_games=false;
string students[6];
string teachers[4];
string students_playing_games[6];
string students_been_caught[6];
string students_been_caughted[6];
string if_come=" came!";
string if_left=" left!";
string student_continue_playing_games=" started playing games!";
string student_stop_playing_games=" stopped playing games!";
string news;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//FASTTTTTTTTTTTTTTTT cin & cout
cin>>n;
for(int i=1;i<=3;i++)
{
cin>>teachers[i];
}
for(int i=1;i<=5;i++)
{
cin>>students[i];
}
getline(cin,news);
for(int i=1;i<=n;i++)
{
getline(cin,news);
for(int y=1;y<=3;y++)
{
if(teachers[y]+if_come == news)//老师来了吗
{
teacher_comes = true;
break;
}
}
for(int y=1;y<=3;y++)
{
if(teachers[y]+if_left == news)//老师走了吗
{
teacher_comes = false;
break;
}
}
for(int y=1;y<=5;y++)
{
if(students[y]+student_continue_playing_games == news)//有人van游戏吗
{
is_there_any_student_playing_games=true;
students_playing_games[y]=students[y];
break;
}
}
for(int y=1;y<=5;y++)
{
if(students[y]+student_stop_playing_games == news)//有人不想再van了吗
{
is_there_any_student_playing_games=false;
students_playing_games[y]="";
break;
}
}
if(is_there_any_student_playing_games && teacher_comes)
{
for(int y=1;y<=5;y++)
{
if((students_playing_games[y] != students_been_caughted[y]) && (students_playing_games[y] != ""))//有没有被抓到?
{
students_been_caught[++sum]=students_playing_games[y];
students_been_caughted[y]=students_been_caught[y];
}
}
}
}
sort(students_been_caught,students_been_caught+sum);
for(int i=1;i<=sum-1;i++)
{
cout<<students_been_caught[i]<<' ';//问题来源(不一定(?
}
cout<<endl;
if(sum==1)
{
cout<<"How Good Oiers Are!"<<endl;
}
if(sum==6)
{
cout<<"How Bad Oiers Are!"<<endl;
}
}