先改动 后验证

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n;
	cin>>n;
	getchar();
	string s[100001];
	for(int i=1;i<=n;i++)
	{
		cin>>s[i];
		ll l=s[i].size();
		for(int j = 0; j < l; j++) {
            if(s[i][j] == '9') s[i][j] = '6';
        }
		if(i>1)
		{
			if(s[i].size()>s[i-1].size())continue;
			if(s[i]>=s[i-1]) continue;
			if(s[i]<s[i-1])//此数比上一个数字小
			{	
				if(l<s[i-1].size())
				{
					cout<<"impossible";
					return 0;
				 } 
				 for(int j=0;j<l;j++)
				 {
				 	if(s[i][j]=='6')
				 	s[i][j]='9';
				 }
				 if(s[i]<s[i-1])
				 {
				 	cout<<"impossible";
				 	return 0;
				 }
				 else
				 {
				 	for(int k = 0; k < l; k++) {
                    if(s[i][k] == '9') {
                        s[i][k] = '6';
                        if(s[i] < s[i-1]) {
                            s[i][k] = '9';
                        }
                    }
                }
				 }
			 } 
		}
	
	}
	cout << "possible" << endl;
    for(int i = 1; i <= n; i++) {
        cout << s[i] << endl;
    }
}

I . In-place Sorting [ 问题 8048 ] [ 讨论 ]
Description
Woe is you – for your algorithms class you have to write a sorting algorithm, but you missed the relevant lecture! The subject was in-place sorting algorithms, which you deduce must be algorithms that leave each input number in its place and yet somehow also sort the sequence.

Of course you cannot change any of the numbers either, then the result would just be a different sequence. But then it hits you: if you flip a 6 upside-down, it becomes a 9, and vice versa! Certainly no one can complain about this since you changed none of the digits! The deadline to hand in the exercise is in five hours. Try to implement this sorting algorithm before then!

Input
The input consists of:

A line with an integer n (2≤n≤10000), the number of integers in the input sequence.
n lines, the ith of which contains a positive integer xi (1≤xi≤1018), the ith number of the sequence.
Output
If the sequence cannot be sorted in non-decreasing order by flipping some of the digits 6 or 9 in the input(Flipping any of the digits of n is not allowed.), output “impossible”. Otherwise, output “possible” followed by the sorted sequence – each number on its own line.

If there is more than one valid solution, please output the smallest sequence.

Samples
Input 复制
4
9
7
7
9
Output
possible
6
7
7
9
Input 复制
4
97
96
66
160
Output
possible
67
69
69
160
Input 复制
3
80
97
79
Output
impossible
Input 复制
2
197
166
Output
possible
167
169
Source
BAPC 2020 Preliminaries

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值