TAG 括号匹配
偶然发现一道自己之前没ac的题,而且都是CE。
刚好现在弄清楚了,大数组要放到main函数外。不然会有奇怪的错误。跟编译时数据的分配位置有关。
i686-linux-4.4.........crt1.o: In function `_start': (.text+0x18): undefined reference to `main' collect2: ld returned 1 exit status
赶紧改一改然后ac。当作括号匹配做。。
// source code of submission 297499, Zhongshan University Online Judge System
#include<cstdio>
#include<memory>
#include<stack>
using namespace std;
int couple[200005];
int main()
{
int n;
while (scanf("%d", &n), n!=0)
{
int x,y;
stack<int> match;
bool ok=true;
int k=0;
for (int i=0; i<n; ++i)
{
scanf("%d%d",&x, &y);
if (ok)
{
ok= ( (x-y)%2+2 )%2==1;
}
couple[ x-1 ]=k;
couple[ y-1 ]=k;
++k;
}
if ( !ok )
{
printf("No/n");
continue;
}
match.push( couple[0] );
for (int i=1; i<2*n; ++i)
{
if( match.empty() || couple[i]!=match.top() )
{
match.push(couple[i]);
}
else
{
match.pop();
}
}
if ( match.empty() )
{
printf("Yes/n");
}
else
{
printf("No/n");
}
}
return 0;
}