Pagini recente » Cod sursa (job #793893) | Cod sursa (job #2751819) | Cod sursa (job #2587213) | Cod sursa (job #2822238) | Cod sursa (job #1340829)
#include <cstdio>
#include <string>
#include <vector>
using namespace std;
#define FIN "convertor.in"
#define FOUT "convertor.out"
inline int is_whitespace(char c)
{
return c < 33;
//return c == ' ' || c == '\n' || c == '\t' || c == '\r';
}
int main()
{
vector <string> headers, elements;
string str;
char c;
int H, fline, i;
freopen(FIN, "r", stdin);
freopen(FOUT, "w", stdout);
for (fline = 1; scanf("%c", &c); )
{
if (is_whitespace(c))
continue;
if (c == '}')
fline = 0;
else if (c == ']')
break;
else if (c == '"')
{
for (str.clear(), scanf("%c", &c); c != '"'; scanf("%c", &c))
str.push_back(c);
if (fline)
headers.push_back(str);
}
if (c == ':')
{
for (scanf("%c", &c); is_whitespace(c); scanf("%c", &c));
if (c == '"')
for (str.clear(), scanf("%c", &c); c != '"'; scanf("%c", &c))
str.push_back(c);
else
for (str.clear(); c >= '0' && c <= '9'; scanf("%c", &c))
str.push_back(c);
elements.push_back(str);
}
if (c == ']')
break;
}
H = headers.size();
for (i = 0; i < H; ++ i)
printf("%s,", headers[i].c_str());
for (i = 0; i < elements.size(); ++ i)
{
if (i % H == 0)
printf("\n");
printf("%s,", elements[i].c_str());
}
printf("\n");
}