Ref Link #include <iostream> #include <map> #include <string> #include <algorithm> using namespace std; map<char,int> memo; int main() { int t, next; string s; cin >> t; for(int k = 1; k <= t; k++) { cin >> s; memo.clear(); // number does not start with 0 so min value for the first char is 1 memo[s[0]] = 1; //next value to assign to a symbol next = 0; for(int i = 1; i < s.size(); i++) { if(memo.count(s[i]) == 0) { memo[s[i]] = next++; ...