题解 | #胜者为王#
胜者为王
http://www.nowcoder.com/questionTerminal/30f4b20a4d5b481a954eada2e9d1af97
#include<iostream> #include<algorithm> using namespace std; int main() { int n; cin>>n; string s1,s2,s3; cin>>s1>>s2>>s3; int len=(int)s1.length(); char abc[3]; int nums[3]={0,0,0}; for(int i=0;i<128;i++) { int num123[3]={(int)count(s1.begin(),s1.end(),i),(int)count(s2.begin(),s2.end(),i),(int)count(s3.begin(),s3.end(),i)}; for(int j=0;j<3;j++) { if(num123[j]>nums[j]) { nums[j]=num123[j]; abc[j]=i; } } } int imax=max({nums[0],nums[1],nums[2]}); if((len-imax)<n) { for(int i=0;i<3;i++) { if((len-nums[i])<n) { nums[i]=len; } } imax=len; } if(((nums[0]==imax) && (nums[0]==nums[1] || nums[0]==nums[2])) || (nums[2]==nums[1] && nums[2]==imax)) { cout<<"draw"<<endl; } else if(imax==nums[0]) { cout<<"xiaoming"<<endl; } else if(imax==nums[1]) { cout<<"xiaowang"<<endl; } else if(imax==nums[2]) { cout<<"xiaoli"<<endl; } }