結果

問題 No.423 ハムスター語初級(数詞)
ユーザー SotaSota
提出日時 2022-05-24 21:12:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,792 bytes
コンパイル時間 864 ms
コンパイル使用メモリ 98,320 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 18:55:38
合計ジャッジ時間 1,447 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES

#include <iostream>		//cin, cout
#include <vector>		//vector
#include <algorithm>	//sort,min,max,count
#include <string>		//string,getline, to_string
#include <cstdlib>		//abs(int)
#include <utility>		//swap, pair
#include <deque>		//deque
#include <climits>		//INT_MAX
#include <bitset>		//bitset
#include <cmath>		//sqrt, ceil. M_PI, pow, sin
#include <ios>			//fixed
#include <iomanip>		//setprecision
#include <sstream>		//stringstream
#include <numeric>		//gcd, assumlate
#include <random>		//randam_device
#include <limits>		//numeric_limits

using namespace std;
constexpr long long int D_MOD = 1000000007;

inline unsigned int BinToUInt(const string S) {
	//2進数(文字列)を10進数(unsigned int)に変換する

	unsigned int result = 0;
	for (unsigned int i = 0; i < S.length(); i++) {
		switch (S[i]) {
		case '0':result *= 2; break;
		case '1':result = result * 2 + 1; break;
		}
	}
	return result;
}

inline string UIntToBin(unsigned int a) {
	//10進数(unsigned int)を2進数(文字列)に変換する

	if (a == 0) { return "0"; }	
	string str;
	while (a != 0) {
		if (a % 2 == 0) { str.insert(str.begin(), '0'); }
		else { str.insert(str.begin(), '1'); }
		a >>= 1;
	}
	return str;
}

int main() {

	string n;
	cin >> n;

	string a;
	for (unsigned int i = 0; i < n.length(); i++) {
		if (n[i] == 'm') {
			if (i == n.length() - 1) {
				a.push_back('0');
			}
			else {
				if (n[i + 1] == 'u') {
					a.push_back('1');
				}
				else {
					a.push_back('0');
				}
			}
		}
	}

	unsigned int temp = BinToUInt(a);
	temp *= 2;
	string result = UIntToBin(temp);

	string ans;
	for (unsigned int i = 0; i < result.length(); i++) {
		ans = ans + "ham";
		if (result[i] == '1') {
			ans.push_back('u');
		}
	}

	cout << ans << endl;

	return 0;

}
0