Pagini recente » Cod sursa (job #367821) | Cod sursa (job #788095) | Cod sursa (job #3127337) | Cod sursa (job #1090557) | Cod sursa (job #1340822)
#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, x;
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);
}
}
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");
}