第一题
豚鼠排名榜
题目描述
已知字符A.B,C。每个字符都有自己的权值q。 现不知道权值q,只知道A,B,C的三次比较结果。
输入描述:
输入三个字符串表示三次比较的结果
输出描述:
输出结果,如果不存在输出”Impossible”
输入样例
AB>C
C>A
输出样例
ACB
题解
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
unordered_map<char,int> m;
string solution(string exp1, string exp2,string exp3) {
vector<string> t = {exp1,exp2,exp3};
m['A'] = m['B'] = m['C'] = 0;
for(auto x : t) {
if (x[1] == '>') m[x[0]]++;
else m[x[2]]++;
}
string res = "ABC";
int cnt[3] = {0};
for (auto x : m) {
cnt[x.second]++;
res[x.second] = x.first;
}
for