Submission #446860

#TimeUsernameProblemLanguageResultExecution timeMemory
446860ComPhyParkCrayfish scrivener (IOI12_scrivener)C++14
Compilation error
0 ms0 KiB
#include<cstdio> #include<malloc.h> #include<vector> using namespace std; int n; typedef struct node { int depth; char data; node* anc[22]; node* child[26]; void init(char d, node* par) { data = d; if (par != NULL) { depth = par->depth + 1; } else depth = 0; int i = 0; anc[0] = par; while (anc[i] != NULL) { i++; anc[i] = anc[i - 1]->anc[i - 1]; } for (; i < 22; i++)anc[i] = NULL; for (int i = 0; i < 26; i++)child[i] = NULL; } node* getChild(char nxt) { if (child[nxt - 'a'] == NULL) { child[nxt - 'a'] = (node*)malloc(sizeof(node)); child[nxt - 'a']->init(nxt, this); } return child[nxt - 'a']; } char getAnc(int d) { if (!d)return data; int i = 0; while (!(d & 1)) { d >>= 1; i++; } return anc[i]->getAnc((d ^ 1) << i); } }node; vector<node*>v; void Init(int N) { n = N; node* nd = (node*)malloc(sizeof(node)); nd->init(0, NULL); v.push_back(nd); } void TypeLetter(char a) { v.push_back(v.back()->getChild(a)); } void UndoCommands(int a) { v.push_back(v[v.size() - a - 1]); } char GetLetter(int a) { return v.back()->getAnc(v.back()->depth - a - 1); } case 'P': scanf("%d", &d); printf("%c\n", GetLetter(d)); break; case 'U': scanf("%d", &d); UndoCommands(d); break; default: while(1)printf("BUG--"); } } return 0; }

Compilation message (stderr)

scrivener.cpp:59:3: error: expected unqualified-id before 'case'
   59 |   case 'P':
      |   ^~~~
scrivener.cpp:61:10: error: expected constructor, destructor, or type conversion before '(' token
   61 |    printf("%c\n", GetLetter(d));
      |          ^
scrivener.cpp:62:4: error: expected unqualified-id before 'break'
   62 |    break;
      |    ^~~~~
scrivener.cpp:63:3: error: expected unqualified-id before 'case'
   63 |   case 'U':
      |   ^~~~
scrivener.cpp:65:16: error: expected constructor, destructor, or type conversion before '(' token
   65 |    UndoCommands(d);
      |                ^
scrivener.cpp:66:4: error: expected unqualified-id before 'break'
   66 |    break;
      |    ^~~~~
scrivener.cpp:67:3: error: expected unqualified-id before 'default'
   67 |   default:
      |   ^~~~~~~
scrivener.cpp:69:3: error: expected declaration before '}' token
   69 |   }
      |   ^
scrivener.cpp:70:2: error: expected declaration before '}' token
   70 |  }
      |  ^
scrivener.cpp:71:2: error: expected unqualified-id before 'return'
   71 |  return 0;
      |  ^~~~~~
scrivener.cpp:72:1: error: expected declaration before '}' token
   72 | }
      | ^