結果

問題 No.423 ハムスター語初級(数詞)
ユーザー ElkElk
提出日時 2018-07-21 19:58:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,164 bytes
コンパイル時間 1,628 ms
コンパイル使用メモリ 168,236 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-27 00:44:40
合計ジャッジ時間 2,021 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int func1(string str){
    int ans = 0, i;
    for(i = 0; i < str.size(); i++){
        if(str[i] == '1'){
            ans += pow(2, str.size() - 1 - i);
        }
    }

    return ans;
}

string func2(int num){
    string str, tmp;
    int i;
    while(1){
        tmp += to_string(num%2);
        num /= 2;
        //printf("num %d\n", num);
        if(num == 1){
            tmp += to_string(num%2);
            break;
        }
    }
    for(i = 0; i < tmp.size(); i++){
        if(tmp[tmp.size() - 1 - i] == '1'){
            str += "hamu";
        }else{
            str += "ham";
        }
    }
    return str;
}

int main(){
    string str, ans;
    int cnt, i, tmp;

    cin >> str;

    if(str == "ham"){
        cout << "ham" << endl;
        return 0;
    }else{
        for(i = 0; i < str.size(); i += cnt){
            if(strncmp(&str[i], "hamu", 4) == 0){
                ans += '1';
                cnt = 4;
            }else{
                ans += '0';
                cnt = 3;
            }
        }
    }
    tmp = func1(ans);
    ans = func2(tmp*2);

    cout << ans << endl;

    return 0;
}
0