C++
- @ignis_fatuus
- ブン
- @Linda_pp
- 清楚なC++メイドBOT
- @tzik_tack
- 長谷川一輝
- wraith13
- @jj1bdx
- @cpp_akira
- 安藤敏彦
- @srz_zumix
- Siv3D
- @okdshin
- @hnokx
- @ishidakei
- @take_cheeze
- TAKEI Yuya
- @mumumu
- I (@wx257osn2)
- Tommy6
- わたやん
- @KorekaraSEDB
- @kariya_mitsuru
- @ciniml
- @beam2d
- @grafi_tt
- @nekketsuuu
- LouiS0616
- @volanja
- 大鎌広
- むてら
- ガチKGB
- 三重野賢人
x
39
1
2
3
4
5
6
7
8
9
10
std::vector<uint8_t> hex_decode(std::string input){
11
std::vector<uint8_t> output;
12
13
for (int i = 0; i < input.length(); i+=2) {
14
output.push_back(0);
15
}
16
17
for (int i = 0; i < input.length(); i+=2) {
18
uint8_t n = 0;
19
std::stringstream ss;
20
ss << input[i];
21
ss >> std::hex >> n;
22
n = n <<4;
23
output[i/2] += n;
24
ss >> std::hex >> n;
25
output[i/2] += n;
26
}
27
}
28
29
30
int main(int argc, char** argv) {
31
std::string input;
32
std::vector<uint8_t> decode;
33
std::cin >> input;
34
35
decode = hex_decode(input);
36
for (auto&& b : decode) {
37
std::cout << b;
38
}
39
}
$ g++ prog.cc -Wall -Wextra -std=c++2a
Start
prog.cc: In function 'std::vector<unsigned char> hex_decode(std::string)': prog.cc:13:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 13 | for (int i = 0; i < input.length(); i+=2) { | ~~^~~~~~~~~~~~~~~~ prog.cc:17:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 17 | for (int i = 0; i < input.length(); i+=2) { | ~~^~~~~~~~~~~~~~~~ prog.cc:27:1: warning: no return statement in function returning non-void [-Wreturn-type] 27 | } | ^ prog.cc: In function 'int main(int, char**)': prog.cc:30:14: warning: unused parameter 'argc' [-Wunused-parameter] 30 | int main(int argc, char** argv) { | ~~~~^~~~ prog.cc:30:27: warning: unused parameter 'argv' [-Wunused-parameter] 30 | int main(int argc, char** argv) { | ~~~~~~~^~~~
Segmentation fault
Finish