yukicoder No.423 ハムスター語初級(数詞)
問題概要
省略
解法
2進数で表したときに、2倍すると、1桁左に移動するので、末尾に0をつければよい。すなわち、hamをつければいい。
ex1)
101(5)
1010(10)
ex2)
111(7)
1110(14)
注意しなければならないのは、n=hamの時0なので、2倍しても0のまま。
ミス
一発ACのひと凄すぎる。
コード
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <queue> #include <cstdio> #include <cmath> using namespace std; typedef long long ll; #define fi first #define se second #define rep(i,n) for(int i=0;i<(n);i++) int main(void){ string n; cin >> n; if(n == "ham"){ printf("ham\n"); return 0; } cout << n + "ham" << endl; return 0; }