提交时间:2023-11-02 19:14:58

运行 ID: 29732

#include<iostream> #include<string> using namespace std; string str[10]={}; int a[11],n,m,s=0,cnt=10; //输入 n=3, 1 1 1 3 3 3 1 1 1 1 int main() { cin>>n>>m; for(int i=0;i<n;i++){ cin>>str[i]; if(str[i]=="tiger"||str[i]=="lion"||str[i]=="dinosaur"){ a[i]=3; } else a[i]=1; } cnt=n; int i=0; while(cnt>1){ if(a[i]>0) s++; if(s==m) { a[i]--; if(a[i]==0) cnt--; s=0; } i++; i%=10; } for(int i=0;i<n;i++){ if(a[i]) cout<<"森林之王是:"<<str[i]; } return 0; }