兩個(gè)字符串之間打戰(zhàn),相同的字符抵消赠堵,看哪邊剩余的字符多小渊,哪邊獲勝。如果左邊字符串有兩個(gè)字符l茫叭,右邊有一個(gè)字符l酬屉,則只抵消兩邊的一個(gè)l,因此左邊字符串還剩一個(gè)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;
}