水题~
View Code
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXW = 1024;
const int MAXL = 1024000;
int nw;
bool ok;
char input[MAXL];
char word[MAXW][MAXL];
void work(int start,int end)
{
if (start > end) return;
if (start == end && word[start][0] == 'w')
{
int f = strchr(word[start],'(') - word[start];
int e = strchr(word[start],')') - word[start];
for (int i = f + 2;i < e - 1;i++)
{
ok = true;
printf("%c",word[start][i]);
}
return;
}
int cntif = 0;
int idx = -1;
for (int i = start + 1;i <= end;i++)
if (word[i][0] == 'i') cntif++;
else if (word[i][0] == 'e')
{
if (cntif == 0)
{
idx = i;
break;
}
cntif--;
}
if (word[start][3] == '1')
{
if (idx == -1) work(start + 1,end);
else work(start + 1,idx - 1);
}
else
if (idx != -1)
work(idx + 1,end);
}
int main()
{
int idx;
while (gets(input))
{
nw = 0;
for(idx = 0;input[idx] && input[idx] == ' ';idx++) ;
for (int i = idx;input[i];i++)
if (i == 0 || (input[i-1] == ' ' && input[i] != ' '))
sscanf(input + i,"%s",word[nw++]);
while (gets(input) && strlen(input) != 0)
{
for(idx = 0;input[idx] && input[idx] == ' ';idx++) ;
for (int i = idx;input[i];i++)
if (i == 0 || (input[i-1] == ' ' && input[i] != ' '))
sscanf(input + i,"%s",word[nw++]);
}
ok = false;
work(0,nw - 1);
if(ok) printf("\n");
}
return 0;
}