求助Unknown Error
查看原帖
求助Unknown Error
699852
bzzltl楼主2023/1/10 11:28

本地编译和洛谷IDE都可运行,提交上显示Unknown Error。

代码如下

#include<bits/stdc++.h>
#include<string>
#define N 1000001
using namespace std;
inline int read(){int x=0,y=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-') y=-y;c=getchar();}while(c>='0'&&c<='9'){x=x*10+(c^'0');c=getchar();}return x*y;}

char s[100005];
struct node{
	char num;
	int id;	
}ch[N];
int sum[N],cnt;
int l1,l2;

signed main()
{
	cin>>s;
	for(int i=0;i<strlen(s);i++)
	{
		if(s[i]=='1') sum[i]++,l1++;
		else 
		{
			ch[++cnt].num=s[i];
			ch[cnt].id=i;
			if(s[i]=='2') l2++;
		}
		sum[i]+=sum[i-1];
	}
	int op=0,pos=0;
	int pd=1;
	while(l1&&l2)
	{
		op++;
		if(ch[op].num=='0') printf("0");
		else if(ch[op].num=='2'&&pd)
		{
			for(int i=1;i<=l1;i++) printf("1");
			pd=0;
			printf("2");
		}
		else if(ch[op].num=='2'&&!pd) printf("2");
		if(op==cnt) break;
	}
	if(l1==0)
	{
		for(int i=1;i<=cnt;i++)
			cout<<ch[i].num;
	}
	else if(l2==0)
	{
		for(int i=1;i<=cnt;i++) printf("0");
		for(int i=1;i<=l1;i++) printf("1");
	}
	return 0;
}

2023/1/10 11:28
加载中...