Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // hex-to-oct
- //
- // Created by aaron67 on 2017/1/23.
- // Copyright © 2017年 aaron67. All rights reserved.
- //
- #include <iostream>
- #include <iomanip>
- #include <sstream>
- #include <string>
- #include <fstream>
- using namespace std;
- int main(int argc, const char * argv[]) {
- ifstream input_file("input.txt");
- ofstream output_file("output.txt");
- int n_test_cases;
- input_file >> n_test_cases;
- while (n_test_cases--) {
- string hex_text;
- input_file >> hex_text;
- int i = hex_text.length() % 3;
- if (i == 0) {
- i = 3;
- }
- stringstream ss;
- ss << hex_text.substr(0, i);
- int j;
- ss >> hex >> j;
- output_file << oct << j;
- while (i < hex_text.length()) {
- ss.clear();
- ss << hex_text.substr(i, 3);
- int j;
- ss >> hex >> j;
- output_file << oct << setw(4) << setfill('0') << j;
- i += 3;
- }
- output_file << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement