4e41a11c38 2011-06-18 kinaba: #include <iostream> 4e41a11c38 2011-06-18 kinaba: #include <sstream> 4e41a11c38 2011-06-18 kinaba: #include <iomanip> 4e41a11c38 2011-06-18 kinaba: #include <vector> 4e41a11c38 2011-06-18 kinaba: #include <string> 4e41a11c38 2011-06-18 kinaba: #include <map> 4e41a11c38 2011-06-18 kinaba: #include <set> 4e41a11c38 2011-06-18 kinaba: #include <algorithm> 4e41a11c38 2011-06-18 kinaba: #include <numeric> 4e41a11c38 2011-06-18 kinaba: #include <iterator> 4e41a11c38 2011-06-18 kinaba: #include <functional> 4e41a11c38 2011-06-18 kinaba: #include <complex> 4e41a11c38 2011-06-18 kinaba: #include <queue> 4e41a11c38 2011-06-18 kinaba: #include <stack> 4e41a11c38 2011-06-18 kinaba: #include <cmath> 4e41a11c38 2011-06-18 kinaba: #include <cassert> 4e41a11c38 2011-06-18 kinaba: #include <cstring> 4e41a11c38 2011-06-18 kinaba: using namespace std; 4e41a11c38 2011-06-18 kinaba: typedef long long LL; 4e41a11c38 2011-06-18 kinaba: typedef complex<double> CMP; 4e41a11c38 2011-06-18 kinaba: 4e41a11c38 2011-06-18 kinaba: class LuckyRemainder { public: 4e41a11c38 2011-06-18 kinaba: int getLuckyRemainder(string X) 4e41a11c38 2011-06-18 kinaba: { 4e41a11c38 2011-06-18 kinaba: int sum = 0; 4e41a11c38 2011-06-18 kinaba: int N = X.size()-1; 4e41a11c38 2011-06-18 kinaba: for(int i=0; i<X.size(); ++i) 4e41a11c38 2011-06-18 kinaba: { 4e41a11c38 2011-06-18 kinaba: int v = X[i]-'0'; 4e41a11c38 2011-06-18 kinaba: for(int i=0; i<N; ++i) 4e41a11c38 2011-06-18 kinaba: v = (v*2)%9; 4e41a11c38 2011-06-18 kinaba: sum = (sum+v)%9; 4e41a11c38 2011-06-18 kinaba: } 4e41a11c38 2011-06-18 kinaba: return sum; 4e41a11c38 2011-06-18 kinaba: } 4e41a11c38 2011-06-18 kinaba: }; 4e41a11c38 2011-06-18 kinaba: 4e41a11c38 2011-06-18 kinaba: // BEGIN CUT HERE 4e41a11c38 2011-06-18 kinaba: #include <ctime> 4e41a11c38 2011-06-18 kinaba: double start_time; string timer() 4e41a11c38 2011-06-18 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 4e41a11c38 2011-06-18 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 4e41a11c38 2011-06-18 kinaba: { os << "{ "; 4e41a11c38 2011-06-18 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 4e41a11c38 2011-06-18 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 4e41a11c38 2011-06-18 kinaba: void verify_case(const int& Expected, const int& Received) { 4e41a11c38 2011-06-18 kinaba: bool ok = (Expected == Received); 4e41a11c38 2011-06-18 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 4e41a11c38 2011-06-18 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 4e41a11c38 2011-06-18 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 4e41a11c38 2011-06-18 kinaba: #define END verify_case(_, LuckyRemainder().getLuckyRemainder(X));} 4e41a11c38 2011-06-18 kinaba: int main(){ 4e41a11c38 2011-06-18 kinaba: 4e41a11c38 2011-06-18 kinaba: CASE(0) 4e41a11c38 2011-06-18 kinaba: string X = "123"; 4e41a11c38 2011-06-18 kinaba: int _ = 6; 4e41a11c38 2011-06-18 kinaba: END 4e41a11c38 2011-06-18 kinaba: CASE(1) 4e41a11c38 2011-06-18 kinaba: string X = "24816"; 4e41a11c38 2011-06-18 kinaba: int _ = 3; 4e41a11c38 2011-06-18 kinaba: END 4e41a11c38 2011-06-18 kinaba: CASE(2) 4e41a11c38 2011-06-18 kinaba: string X = "8"; 4e41a11c38 2011-06-18 kinaba: int _ = 8; 4e41a11c38 2011-06-18 kinaba: END 4e41a11c38 2011-06-18 kinaba: CASE(3) 4e41a11c38 2011-06-18 kinaba: string X = "11235813213455"; 4e41a11c38 2011-06-18 kinaba: int _ = 7; 4e41a11c38 2011-06-18 kinaba: END 4e41a11c38 2011-06-18 kinaba: CASE(4) 4e41a11c38 2011-06-18 kinaba: string X = "1"; 4e41a11c38 2011-06-18 kinaba: int _ = 1; 4e41a11c38 2011-06-18 kinaba: END 4e41a11c38 2011-06-18 kinaba: CASE(4) 4e41a11c38 2011-06-18 kinaba: string X = "4"; 4e41a11c38 2011-06-18 kinaba: int _ = 4; 4e41a11c38 2011-06-18 kinaba: END 4e41a11c38 2011-06-18 kinaba: CASE(4) 4e41a11c38 2011-06-18 kinaba: string X = "9"; 4e41a11c38 2011-06-18 kinaba: int _ = 0; 4e41a11c38 2011-06-18 kinaba: END 4e41a11c38 2011-06-18 kinaba: /* 4e41a11c38 2011-06-18 kinaba: CASE(5) 4e41a11c38 2011-06-18 kinaba: string X = ; 4e41a11c38 2011-06-18 kinaba: int _ = ; 4e41a11c38 2011-06-18 kinaba: END 4e41a11c38 2011-06-18 kinaba: */ 4e41a11c38 2011-06-18 kinaba: } 4e41a11c38 2011-06-18 kinaba: // END CUT HERE