結果

問題 No.9006 マルチバイト文字テスト(テスト用)
ユーザー なおなお
提出日時 2015-03-25 03:17:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,347 bytes
コンパイル時間 1,962 ms
コンパイル使用メモリ 148,612 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 10:05:26
合計ジャッジ時間 1,749 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

const u32string utf8to32(const string &s){
    u32string r;auto it=s.begin();
    while(it!=s.end()){
        uint8_t c0=*it++;
        if((c0&0x80)==0)r+=(uint32_t)c0;
        else if((c0&0xE0)==0xC0){uint8_t c1=*it++;r+=(uint32_t)(((c0&0x1F)<<6)|(c1&0x3F));}
        else if((c0&0xF0)==0xE0){uint8_t c1=*it++;uint8_t c2=*it++;r+=(uint32_t)(((c0&0x0F)<<12)|((c1&0x3F)<<6)|(c2&0x3F));}
        else if(0xF0<=c0&&c0<=0xF4){uint8_t c1=*it++;uint8_t c2=*it++;uint8_t c3=*it++;r+=(uint32_t)((c0<<16)|((c1&0x0F)<<12)|((c2&0x3F)<<6)|(c3&0x3F));}
        else throw;
    }
    return r;
}
const string utf32to8(const u32string &s){
    string r;auto it=s.begin();
    while(it!=s.end()){
        uint32_t c0=*it++;
        if((c0&~0x7F)==0)r+=(uint8_t)c0;
        else if((c0&~0x7FF)==0){r+=(uint8_t)(0xC0|(c0>>6));r+=(uint8_t)(0x80|(c0&0x3F));}
        else if((c0&~0xFFFF)==0){r+=(uint8_t)(0xE0|(c0>>12));r+=(uint8_t)(0x80|((c0>>6)&0x3F));r+=(uint8_t)(0x80|(c0&0x3F));}
        else if(c0&0x1F0000){r+=(uint8_t)(0xF0|(c0>>18));r+=(uint8_t)(0x80|((c0>>12)&0x3F));r+=(uint8_t)(0x80|((c0>>6)&0x3F));r+=(uint8_t)(0x80|(c0&0x3F));}
        else throw;
    }
    return r;
}

int main(){
    string s; cin >> s;
    u32string t = utf8to32(s);
    reverse(t.begin(), t.end());
    cout << utf32to8(t) << endl;
}
0