20pts,求hack
查看原帖
20pts,求hack
389955
WillW_Chen楼主2023/1/4 15:54
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<stack>
#include<ctime>
#include<random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MAXN=1e6+50;
string s;
string a[100];
string ans[100];
int len,tot;
int cnt;
string z="0:";
string alph(int x){
	char k='A'+x-1;
	string kk="";
	kk+=k;
	return kk;
}
int num(string x){
	return x[0]-'A'+1;
}
int main(){
	cin>>s;
	string tmp="";
	for(int i=0;i<s.size();i++){
		if(s[i]==':'){
			a[++len]=tmp;
			tmp="";
		}
		else{
			tmp+=s[i];
		}
	}
	a[++len]=tmp;
	for(int i=1;i<=len;i++){
		bool allzero=true;
		for(int j=0;j<a[i].size();j++){
			if(a[i][j]!='0'){
				allzero=false;
				break;
			}
		}
		if(allzero){
			cnt=0;
			while(i<=len){
				i++;
				cnt++;
				for(int j=0;j<a[i].size();j++){
					if(a[i][j]!='0'){
						allzero=false;
						break;
					}
				}
				if(!allzero){
					i--;
					break;
				}
			}
			ans[++tot]=alph(cnt);
			continue;
		}
		string tmp1="";
		int index=0;
		for(int j=0;j<a[i].size();j++){
			if(a[i][j]=='0'){
				index=j+1;
			}
			else{
				break;
			}
		}
		for(int j=index;j<=a[i].size();j++){
			tmp1+=a[i][j];
		}
		ans[++tot]=tmp1;
	}
	char maxn;
	for(int i=1;i<=tot;i++){
		if('A'<=ans[i][0]&&ans[i][0]<='Z'){
			if(ans[i][0]>maxn){
				maxn=ans[i][0];
			}
		}
	}
	bool used=false;
	if(ans[1][0]==maxn){
		cout<<"::";
		used=true;
	}
	else{
		if('A'<=ans[1][0]&&ans[1][0]<='Z'){
			for(int i=1;i<=ans[1][0]-'A'+1;i++){
				cout<<z;
			}
		}
		else{
			cout<<ans[1]<<':';
		}
	}
	for(int i=2;i<tot;i++){
		if(ans[i][0]==maxn){
			if(!used){
				cout<<':';
				used=true;
			}
			else{
				for(int j=1;j<=ans[i][0]-'A'+1;j++){
					cout<<z;
				}
			}
			continue;
		}
		if('A'<=ans[i][0]&&ans[i][0]<='Z'){
			for(int j=1;j<=ans[i][0]-'A'+1;j++){
				cout<<z;
			}
		}
		else{
			cout<<ans[i]<<':';
		}
	}
	if(tot!=1){
		if(ans[tot][0]==maxn){
			cout<<':';
			used=true;
		}
		else{
			if('A'<=ans[tot][0]&&ans[tot][0]<='Z'){
				for(int i=1;i<=ans[tot][0]-'A';i++){
					cout<<z;
				}
				cout<<'0';
			}
			else{
				cout<<ans[tot];
			}
		}
	}
	return 0;
}
2023/1/4 15:54
加载中...