The_Law

Untitled

Dec 18th, 2018
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.10 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. enum
  6. {
  7.     MAXN = 1000
  8. };
  9.  
  10. typedef struct el
  11. {
  12.     char type;
  13.     int key;
  14.     char s[100 + 1];
  15. } el;
  16.  
  17. el t[MAXN][20];
  18. char buff[20 * 101];
  19.  
  20. int main(void)
  21. {
  22.     FILE* in = fopen("input.txt", "r");
  23.     FILE* out = fopen("output.txt", "w");
  24.  
  25.     int n;
  26.     fscanf(in, "%d\n", &n);
  27.  
  28.     int str = 0;
  29.     while (fgets(buff, 20*101, in))
  30.     {
  31.         int it = 0;
  32.         int col = 0;
  33.  
  34.         while (buff[it] != '\0')
  35.         {
  36.             while ((buff[it] != '\0') && (buff[it] != ';') && (buff[it] != '\n'))
  37.                 ++it;
  38.  
  39.             int curr = it - 1;
  40.  
  41.             _Bool isnum = 1;
  42.             int cnt = 0;
  43.             while ((curr >= 0) && (buff[curr] != ';'))
  44.             {
  45.                 if ((buff[curr] < '0' || '9' < buff[curr]) && (buff[curr] != ' ') && (buff[curr] != '\n'))
  46.                     isnum = 0, ++cnt;
  47.  
  48.                 --curr;
  49.             }
  50.  
  51.             ++curr;
  52.             if ((!isnum) && (cnt == 1) && (buff[curr] == '-'))
  53.                 isnum = 1;
  54.  
  55.             if (isnum)
  56.             {
  57.                 int sum = 0;
  58.  
  59.                 while (buff[curr] == ' ')
  60.                     ++curr;
  61.  
  62.                 while ((curr < it) && (buff[curr] != ' '))
  63.                 {
  64.                     sum = sum * 10 + buff[curr] - '0';
  65.                     ++curr;
  66.                 }
  67.  
  68.                 t[str][col].type = 'i';
  69.                 t[str][col].key = sum;
  70.             }
  71.             else
  72.             {
  73.                 t[str][col].type = 's';
  74.  
  75.                 int j = 0;
  76.  
  77.                 while (buff[curr] != '"')
  78.                     ++curr;
  79.                 ++curr;
  80.  
  81.                 while ((curr < it) && (buff[curr] != '"'))
  82.                 {
  83.                     t[str][col].s[j] = buff[curr];
  84.                     ++curr;
  85.                     ++j;
  86.                 }
  87.  
  88.                 t[str][col].s[j] = '"';
  89.                 ++j;
  90.                 t[str][col].s[j] = '\0';
  91.             }
  92.  
  93.             ++it;
  94.             ++col;
  95.         }
  96.  
  97.         ++str;
  98.     }
  99.  
  100.  
  101.     return 0;
  102. }
Add Comment
Please, Sign In to add comment