結果
| 問題 |
No.9006 マルチバイト文字テスト(テスト用)
|
| ユーザー |
|
| 提出日時 | 2015-03-25 03:17:24 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,347 bytes |
| コンパイル時間 | 1,347 ms |
| コンパイル使用メモリ | 162,396 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-29 00:46:52 |
| 合計ジャッジ時間 | 1,715 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
ソースコード
#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;
}