結果

問題 No.423 ハムスター語初級(数詞)
ユーザー ElkElk
提出日時 2018-07-21 19:57:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,142 bytes
コンパイル時間 2,632 ms
コンパイル使用メモリ 166,816 KB
実行使用メモリ 385,752 KB
最終ジャッジ日時 2023-08-27 00:44:33
合計ジャッジ時間 6,566 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 << 0 << endl;
    }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