Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<cstdio>
- #include<algorithm>
- #include<vector>
- #include<set>
- #include<map>
- #include<string>
- #include<iostream>
- #include<cstring>
- #include<cctype>
- #include<queue>
- #include<list>
- #include<cstdlib>
- #include<cmath>
- #include<deque>
- using namespace std;
- typedef long long LL;
- typedef pair<int,int> para;
- typedef vector<int> VI;
- typedef vector<vector<int> > VII;
- typedef vector<string> VS;
- #define PB push_back
- #define MP make_pair
- #define F first
- #define S second
- #define FOREACH(a,n) for(__typeof(n.begin())a=(n).begin(); a!=(n).end(); ++a)
- #define REP(i,n) for(int i=0;i<(n);i++)
- #define FOR(i,a,b) for(int i=(a);i<=(b);i++)
- #define FUP(i,a,b) for(int i=(a);i<=(b);i++)
- #define FORD(i,a,b) for(int i=(a);i>=(b);i--)
- #define ALL(x) x.begin(),x.end()
- #define SIZE(x) ((int)x.size())
- char tab[1000010];
- char st[1000000];
- int w = 0;
- LL m;
- LL str_size;
- int stan = 0;
- LL dlug = 0;
- bool chdl(LL ad){
- dlug += ad;
- return dlug <= m;
- }
- void change_d(){
- if(w > 0 && st[w-1] == 'd')
- st[w-1] = 'D';
- else if(w > 0 && st[w-1] == 'D')
- st[w-1] = 'd';
- }
- /*
- STANY:
- 0 - nic szczegolnego
- 1 - koniec wejscia
- 3 - czekam na cyfre lub dwukropek w stringu
- 4 - czekam na dwukropek w stringu bo mialem wiodace zero
- 8 - czekam na znaki w stringu
- 5 - czekam na cyferke w intcie bo bylo 'i'
- 6 - czekam na cyferke w intcie i juz byly jakies
- 7 - czekam na 'e' bo bylo wiodace zero w intcie
- */
- void blad(int pos){
- printf("Error at position %d!\n", pos);
- }
- int main()
- {
- scanf("%lld", &m);
- scanf("%s", tab);
- int g = 0;
- while(1){
- char t = tab[g++];
- if(t == '\0'){ // koniec wejscia
- if(stan == 1) printf("ok\n");
- else blad(g-1); // za wczesnie
- break;
- }
- if(stan == 1){ // mial byc koniec
- blad(g-1);
- break;
- }
- else if(stan == 0){
- if(t >= '0' && t <= '9'){ // zaczyna sie string
- st[w++] = 's';
- if(t == '0') stan = 4;
- else stan = 3;
- str_size = t - '0';
- if(!chdl(1 + 1 + str_size)){ blad(g-1); break; }
- }
- else if(t == 'i'){
- st[w++] = 'i';
- stan = 5;
- if(!chdl(1 + 1 + 1)){ blad(g-1); break; }
- }
- else if(t == 'l'){
- st[w++] = 'l';
- stan = 0;
- if(!chdl(1 + 1)){ blad(g-1); break; }
- }
- else if(t == 'd'){
- st[w++] = 'd'; // XXX: jak zaznaczam value/key ?
- stan = 0;
- if(!chdl(1 + 1)){ blad(g-1); break; }
- }
- else if(t == 'e'){
- if(w == 0){ blad(g-1); break; }
- if(st[w-1] == 'l' || st[w-1] == 'd'){
- w--;
- if(!w) stan = 1; else stan = 0;
- }
- else if(st[w-1] == 'D'){
- // blad - brakuje value bo byl key
- blad(g-1);
- break;
- }
- }
- else{ blad(g-1); break; }
- }
- else if (stan == 3){
- if(t >= '0' && t <= '9'){
- if(!chdl(1LL + str_size * 9 + (t - '0'))){ blad(g-1); break; }
- str_size = str_size * 10 + (t - '0');
- }
- else if(t == ':'){
- stan = 8;
- }
- else{ blad(g-1); break; }
- }
- else if(stan == 4){
- if(t == ':'){ // skonczyl sie string
- w--;
- if(!w) stan = 1; else stan = 0;
- change_d();
- }
- else{ blad(g-1); break; }
- }
- else if(stan == 8){
- if(--str_size == 0){
- stan = 0; // skonczyl sie string
- w--;
- if(!w) stan = 1; else stan = 0;
- change_d();
- }
- }
- else if(stan == 5){
- if(t == '0'){
- stan = 7;
- }
- else if(t >= '1' && t <= '9'){
- stan = 6;
- }
- else{ blad(g-1); break; }
- }
- else if(stan == 6){
- if(t >= '0' && t <= '9'){
- if(!chdl(1)){ blad(g-1); break; }
- }
- else if(t == 'e'){
- w--;
- if(!w) stan = 1; else stan = 0;
- change_d();
- }
- else{ blad(g-1); break; }
- }
- else if(stan == 7){
- if(t == 'e'){
- w--;
- if(!w) stan = 1; else stan = 0;
- change_d();
- }
- else{ blad(g-1); break; }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement