社区讨论

改了半个小时…

P1012[NOIP 1998 提高组] 拼数参与者 3已保存回复 4

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
4 条
当前快照
1 份
快照标识符
@mhjlhpz3
此快照首次捕获于
2025/11/04 04:31
4 个月前
此快照最后确认于
2025/11/04 04:31
4 个月前
查看原帖
CPP
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n;
string a[21];
string Max(string x,string y){
	if(stoi(x) == 0 && stoi(y) != 0) return y;
	else if(stoi(x) != 0 && stoi(y) == 0) return x;
	ll len = min(x.size(),y.size());
	for(ll i = 0; i < len; i++)
	{
		if(x[i] > y[i])
			return x;
		else if(x[i] < y[i])
			return y;
	}
//	len=max(x.size(),y.size());
	if(y[0] - y[y.size()-1] > x[0] - x[x.size()-1]) return x;
	else if(x[0] - x[x.size()-1] > y[0]- y[y.size()-1]) return y;
	else if(y[0] <= y[y.size()-1] && y[y.size()-1] > x[x.size()-1]) return y;
	else return x;
}
int main(){
	
	cin>> n;
	ll len = 0;
	for(int i = 0; i < n; i++)
	{
		cin>> a[i];
		len += a[i].size();
	}
	string ans;
	ll sum = 0;
	for(int i = 0; i < n; i++)
	{
		ans = "0";
		for(int j = 0; j < n; j++)
		{
			ans = Max(ans,a[j]);
		}
		
		len -= ans.size();
		sum += stoi(ans) * pow(10,len);
		
		for(int j = 0; j < n; j++)
		{
			if(a[j] == ans){
				a[j] = '0';
				break;
			}
		}
	}
	cout<<sum;
	return 0;
}
题目 特判也都加上了才75

回复

4 条回复,欢迎继续交流。

正在加载回复...