/ tabris /

记录详情

Compile Error

/in/foo.cc:39:13: warning: missing terminating ' character
    if(s[0]=='f){
             ^
/in/foo.cc:39:13: error: missing terminating ' character
    if(s[0]=='f){
             ^~~~
/in/foo.cc: In function 'int main()':
/in/foo.cc:40:12: error: lvalue required as left operand of assignment
     x=read();y=read();
            ^
/in/foo.cc:40:13: error: expected ')' before ';' token
     x=read();y=read();
             ^
/in/foo.cc:39:4: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
    if(s[0]=='f){
    ^~
/in/foo.cc:40:14: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
     x=read();y=read();
              ^
/in/foo.cc:63:7: error: 's' was not declared in this scope
    if(s=='t'){//x诱惑y 
       ^
/in/foo.cc:73:7: error: 's' was not declared in this scope
    if(s=='r'){//反叛,传位。 
       ^
/in/foo.cc: At global scope:
/in/foo.cc:85:1: error: expected declaration before '}' token
 }
 ^

代码

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=100005;
int fa[maxn<<1],size[maxn<<1],mapped[2*maxn],hui[2*maxn];
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
int n,m,x,y,fx,fy,cnt,next;
int getfa(int x){
	if(fa[x]==x)return x;
	return fa[x]=getfa(fa[x]);
}
int main(){
	int t;
	t=read();
	for(int k=1;k<=t;k++){
		printf("Case #%d:\n",k);
		memset(mapped,0,sizeof(mapped));
		n=read();m=read();
		for(int i=1;i<=n;i++){fa[i]=i;size[i]=1;mapped[i]=i;}
		cnt=n;
		int shu_bangpai=n;
		for(int i=1;i<=m;i++){
			char s[105];
			scanf("%s",s);
			if(s[0]=='q')printf("%d\n",shu_bangpai);
			if(s[0]=='f){
				x=read();y=read();
				fx=getfa(mapped[x]);fy=getfa(mapped[y]);
				if(fx==fy)continue;
				if(size[fx]==size[fy]){
					printf("Either is winner!\n");
					continue;
				}
				shu_bangpai--;
				if(size[fx]>size[fy]){
					size[fx]+=size[fy];
					//size[fy]=0;
					fa[fy]=fx;
					printf("%d is winner!\n",x);
					continue;
				}
				if(size[fx]<size[fy]){
					size[fy]+=size[fx];
					//size[fx]=0;
					fa[fx]=fy;
					printf("%d is winner!\n",y);
					continue;
				}
			}
			if(s=='t'){//x诱惑y 
				x=read();y=read();
				fx=getfa(mapped[x]),fy=getfa(mapped[y]);
				if(fx==fy)continue;
				if(size[fy]==1)shu_bangpai--;
				mapped[y]=++cnt;
				fa[mapped[y]]=mapped[x];
				size[fx]++;
				size[fy]--;
			}
			if(s=='r'){//反叛,传位。 
				x=read();
				fx=getfa(mapped[x]);
				if(size[fx]==1)continue;
				size[fx]--;
				mapped[x]=++cnt;
				fa[mapped[x]]=mapped[x];
				size[mapped[x]]=1;
				shu_bangpai++;
			}
		}
	}
}

信息

递交者
类型
递交
题目
幼儿园战争
语言
C++
递交时间
2019-10-02 19:21:51
评测时间
2019-10-02 19:21:51
评测机
分数
0
总耗时
0ms
峰值内存
0 Bytes