Last active
April 17, 2017 16:00
-
-
Save cthbst/dfde3beafd8e4e154bf6c1af2a81b8b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <msgpack.hpp> | |
#include <iostream> | |
#include <fstream> | |
#include <vector> | |
#include <string> | |
#include <sstream> | |
#include <queue> | |
using namespace std; | |
void finput(const string& filename, vector<string>& ); | |
void foutput(const string& filename, vector<string>& ); | |
void split(string& ins, vector<string>& vec); | |
void append(string& sa,const string& sb); | |
int main(){ | |
static vector<string> inputs, outputs; | |
//finput("input.txt",inputs); | |
finput("input_example.txt",inputs); | |
int T = inputs[0][0]-'0'; // T<=5 | |
outputs.resize(T); | |
append(outputs[0],(string)"aa 0932804251 bb 0932804266"); | |
append(outputs[0],(string)"cc 0932804310"); | |
append(outputs[0],(string)"aa 0932804251 bb 0932804266"); | |
append(outputs[1],(string)"ee 0932804326 ii 0932804354 hh 0932804383 dd 0932804384 ff 0932804402 gg 0932804410"); | |
append(outputs[1],(string)"ii 0932804354"); | |
append(outputs[1],(string)"ee 0932804326 ii 0932804354 hh 0932804383 dd 0932804384 ff 0932804402 gg 0932804410"); | |
append(outputs[1],(string)"hh 0932804383 dd 0932804384"); | |
append(outputs[1],(string)"ff 0932804402 gg 0932804410"); | |
append(outputs[1],(string)"ee 0932804326"); | |
append(outputs[1],(string)"ii 0932804354"); | |
foutput("output.txt",outputs); | |
} | |
void finput(const string &filename, vector<string>& in ){ | |
std::ifstream ifs(filename.c_str(), std::ifstream::in); | |
std::string buffer((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>()); | |
msgpack::unpacker pac; | |
pac.reserve_buffer( buffer.size() ); | |
std::copy( buffer.begin(), buffer.end(), pac.buffer() ); | |
pac.buffer_consumed( buffer.size() ); | |
msgpack::object_handle oh; | |
pac.next(oh); | |
oh.get().convert(in); | |
} | |
void foutput(const string &filename, vector<string>& out ){ | |
msgpack::sbuffer sbuf; | |
msgpack::pack(sbuf, out); | |
fstream outf; | |
outf.open(filename.c_str(), ios::out | ios::binary); | |
outf.write(sbuf.data(), sbuf.size() ); | |
outf.close(); | |
} | |
void split(string &ins, vector<string>& vec){ | |
static stringstream ss; | |
vec.clear(); | |
ss.str(ins); | |
ins.clear(); | |
string s; | |
while (ss >> s)vec.push_back(s); | |
ss.clear(); | |
} | |
void append(string& sa,const string& sb){ | |
if (sa.size()!=0)sa.append(" "); | |
sa.append(sb); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment