## 773 - The JustaPox Language

Moderator: Board moderators

holdonasec
New poster
Posts: 11
Joined: Tue Aug 05, 2014 9:18 am

### Re: 773 - The JustaPox Language

I'm getting TLE with this code, not sure why :<

Code: Select all

``````#include <iostream>
#include <fstream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>

#define PF printf
#define SF scanf

using namespace std;
typedef long long ll;
int itest = 1, ntest = 1;

#define CMAX 5000
#define AMAX 1000

struct lang {
char s[CMAX];
int  num;
int  a[AMAX];
bool isSet;
};

int  la = 0;
lang a[AMAX];
char s[CMAX];
bool isNew;

bool _isNumber(char c)
{
return c >= '0' && c <= '9';
}

bool _isAlpha(char c)
{
return  (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z');
}

int _id(char s[])
{
int i;

for (i=0; i<la; i++)
{
if (strcmp(a[i].s, s) == 0)
{
return i;
}
}

strcpy(a[i].s, s);
a[i].num = 0;
memset(a[i].a, -1, sizeof(a[i].a));
isNew = true;
la++;

return i;
}

int _array(char s[])
{
int i, j, k;
int id, x, result = 0;
int len = strlen(s);
char temp[CMAX];

for (i=0; i<len; i++)
{
if (s[i] == ' ' && s[i+1] == 'i' && s[i+2] == 's')
{
i = i + 3;
break;
}
}

for (; i<len; i++)
{
if ( _isNumber(s[i]) )
{
x = s[i] - '0';

for (j=i+1; j<len; j++)
{
if (!_isNumber(s[j]))
break;

x = x * 10 + s[j] - '0';
}

result += x;
i = j;
}

if (_isAlpha(s[i]))
{
temp[0] = s[i];

for (j=i+1, k=1; j<len; j++, k++)
{
if (!_isAlpha(s[j]))
{
temp[k] = '\0';
break;
}

temp[k] = s[j];
}

id = _id(temp);
result += a[id].num;
i = j;
}
}

return result;
}

{
int i, j, k, l;
int x, result = 0;
int len = strlen(s);
char temp[CMAX];

for (i=0, l=0; i<len; i++)
{
if ( _isNumber(s[i]) )
{
x = s[i] - '0';

for (j=i+1; j<len; j++)
{
if (!_isNumber(s[j]))
break;

x = x * 10 + s[j] - '0';
}

if (a[id].a[l] != x && a[id].a[l] != -1)
return false;

a[id].a[l] = x;

l ++;

if (l > a[id].num)
return false;

i = j;
}
}

return true;
}

void _input()
{
int i, j;
int num, len, id;
char temp[CMAX];

len = strlen(s);

for (i=0; i<len && s[i] != ' '; i++)
{
temp[i] = s[i];
}

temp[i] = '\0';

isNew = false;
id = _id(temp);

if (isNew)
{
a[id].num = _array(s);
return;
}

for (i=0; i<len; i++)
{
if (s[i] == ' ' && s[i+1] == 'i' && s[i+2] == 's')
{
num = _array(s);

if (a[id].num != num)
{
PF("%s\n", s);
}
break;
}

if (s[i] == '=')
{
{
PF("%s\n", s);
}

break;
}
}
}

int main()
{
#ifndef ONLINE_JUDGE
#define FILE_IO "773"
freopen(FILE_IO ".inp", "r", stdin);
//freopen(FILE_IO ".out", "w", stdout);
#endif

while (gets(s) > 0)
{
_input();
}

return 0;
}
``````

holdonasec
New poster
Posts: 11
Joined: Tue Aug 05, 2014 9:18 am

any suggestion?