1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#include <iostream>
#include <fstream>
#include <string>
int main(void)
{
std::ifstream in("input.txt");
std::ofstream out("output.txt");
std::string line;
std::string temp;
size_t firstSpace;
size_t firstParenth;
size_t whiteSpace;
while (getline(in, line))
{
if (line.find("for (UInt32") != std::string::npos)
{
out << line << '\n';
continue;
}
if (line.find(" new ") != std::string::npos)
{
continue;
}
whiteSpace = line.find_first_not_of(" \t");
if (whiteSpace != std::string::npos)
line.erase(0, whiteSpace);
else
{
out << line << '\n';
continue;
}
if (line.find(".Add") != std::string::npos
&& line.find("new") == std::string::npos
)
{
temp = line.substr(0, line.find_first_of('.'));
line.erase(0, line.find_first_of('(') + 1);
temp.append("[(int)i]");
line.insert(line.find_first_of('(') + 1, temp);
line.erase(line.find_last_of(')'), 1);
}
else
{
firstSpace = line.find_first_of(' ');
firstParenth = line.find_first_of('(');
if (firstSpace != std::string::npos
&& firstParenth != std::string::npos
)
{
//insert ( size_t pos1, const string& str, size_t pos2, size_t n );
line.insert(firstParenth + 1, line, 0, firstSpace);
firstSpace = line.find_first_of(' ', firstSpace + 1);
line.erase(0, firstSpace + 1);
}
}
if (line.length() > 1)
{
line.erase(0, line.find_first_of('('));
line.insert(0, "bw.Write");
}
if (whiteSpace != std::string::npos)
line.insert(line.begin(), whiteSpace, ' ');
out << line << std::endl;
}
in.close();
out.close();
return 0;
}
|