两个字符串之间打战,相同的字符抵消,看哪边剩余的字符多,哪边获胜。如果左边字符串有两个字符l,右边有一个字符l,则只抵消两边的一个l,因此左边字符串还剩一个l。
#include <vector>
#include <string>
#include <iostream>
using namespace std;
int compete(string a, string b){
int counter = 0;
vector<int> charVec(26, 0);
//record letter in string a, and add counter
for (int i = 0; i < a.size(); ++i){
++charVec[a[i] - 'a'];
++counter;
}
for (int i = 0; i < b.size(); ++i){
if (charVec[a[i] - 'a'] > 0){
--charVec[a[i] - 'a'];
}
--counter;
}
return counter;
}
int main(){
string a;
string b;
while (true){
cin >> a;
cin >> b;
int k = compete(a, b);
if (k == 0){
cout << "tie" << endl;
}
if (k > 0){
cout << "left win" << endl;
}
if (k < 0){
cout << "right win" << endl;
}
}
return 0;
}