Artifact Content
Not logged in

Artifact 86891d068367bcdf1297f465558bbaec2e2d9aa8


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class EqualizeStrings { public:
	string getEq(string s, string t) 
	{
		string answer;
		for(int i=0; i<s.size(); ++i)
			answer += char(adjust(s[i]-'a', t[i]-'a')+'a');
		return answer;
	}
	int adjust(int x, int y)
	{
		int minC = 9999;
		int minZ = 0;
		for(int z=0; z<26; ++z)
		{
			int c = min(abs(x-z), 26-abs(x-z)) + min(abs(y-z), 26-abs(y-z));
			if( c < minC ) {
				minC = c;
				minZ = z;
			}
		}
		return minZ;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const string& Expected, const string& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, EqualizeStrings().getEq(s, t));}
int main(){

CASE(0)
	string s = "cat"; 
	string t = "dog"; 
	string _ = "caa"; 
END
CASE(1)
	string s = "abcdefghijklmnopqrstuvwxyz"; 
	string t = "bcdefghijklmnopqrstuvwxyza"; 
	string _ = "abcdefghijklmnopqrstuvwxya"; 
END
CASE(2)
	string s = "programmingcompetitionsrule"; 
	string t = "programmingcompetitionsrule"; 
	string _ = "programmingcompetitionsrule"; 
END
CASE(3)
	string s = "topcoderopen"; 
	string t = "onlinerounds"; 
	string _ = "onlcndaoondn"; 
END
CASE(4)
	string s = "a"; 
	string t = "z"; 
	string _ = "a"; 
END
CASE(5)
	string s = "y"; 
	string t = "z"; 
	string _ = "y"; 
END
CASE(5)
	string s = "z"; 
	string t = "b"; 
	string _ = "a"; 
END
CASE(5)
	string s = "h"; 
	string t = "t"; 
	string _ = "h"; 
END
CASE(5)
	string s = "b"; 
	string t = "o"; 
	string _ = "a"; 
END
CASE(5)
	string s = "b"; 
	string t = "n"; 
	string _ = "b"; 
END
CASE(5)
	string s = "b"; 
	string t = "q"; 
	string _ = "a"; 
END
}
// END CUT HERE