比赛 |
20100420 |
评测结果 |
WTWWWWW |
题目名称 |
词法分析程序 |
最终得分 |
0 |
用户昵称 |
lc |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2010-04-20 11:30:04 |
显示代码纯文本
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std;
const int maxn = 1000;
int Tx;
int Lis[maxn][maxn];
char Chp[maxn][maxn];
char state[maxn][30],Start[maxn],ns[maxn];
void Addedge(int x,int y,char ch)
{
Lis[x][0]++;
Lis[x][Lis[x][0]] = y;
Chp[x][Lis[x][0]] = ch;
}
void prep()
{
scanf("%d\n",&Tx);
for (int i=0; i<Tx; i++)
{
scanf("%s\n",&state[i]);
}
for (int i=0; i<Tx; i++)
{
int len;
scanf("%d",&len);
for (int j=1; j<=len; j++)
{
char ch; int num;
scanf(" %c%d",&ch,&num);
Addedge(i,num,ch);
}
}
}
void solve()
{
int P = 0,S = 0,PreS = 0;
while (S <strlen(Start))
{
bool ok = false;
for (int i=1; i<=Lis[P][0]; i++)
{
if (Chp[P][i]==Start[S])
{
P = Lis[P][i]; S++;
ok = true; break;
}
}
if (!ok)
{
if (PreS==S) ns[0] = Start[S];
else for (int i=PreS; i<S; i++) ns[i-PreS] = Start[i];
if (state[P][0]=='-')
{
printf("Lexer Error: %s\n",ns);
return;
}
else
{
printf("%s: %s\n",state[P],ns);
P = 0;
}
PreS = S;
}
}
if (PreS==S) ns[0] = Start[S];
else
for (int i=PreS; i<S; i++) ns[i-PreS] = Start[i];
if (state[P][0]=='-')
{
printf("Lexer Error: %s\n",ns);
}
else
{
printf("%s: %s\n",state[P],ns);
}
}
void work()
{
scanf(" %s",&Start); scanf(" %s",&Start);
while (Start[0]!='$')
{
solve();
scanf(" %s",&Start);
}
}
int main()
{
freopen("lex.in","r",stdin);
freopen("lex.out","w",stdout);
prep();
work();
return 0;
}