贪心 #8#9错了求大佬帮助 Orz
查看原帖
贪心 #8#9错了求大佬帮助 Orz
1171003
zzz987楼主2024/5/29 17:34
#include<iostream>
#include<queue>
#include<algorithm>
#define int long long
using namespace std;
const int N=2e5+9;

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	string s;	cin >>s;
	int a,b;	cin >>a>>b;
	for(int i=0;i<s.size();i++){
		if(a==0&&b==0)	break;
		int x=s[i]-'0';
		int ta=9-x,tb=x+1;
		if(ta<tb){
			if(a>=ta){
				a-=ta;
				s[i]='9';
			}else{
				s[i]=x+a+'0';
				a=0;
			}
		}else{
			if(b>=tb){
				b-=tb;
				s[i]='9';
			}else{
				if(a){
					if(a>=ta){
						a-=ta;
						s[i]='9';
					}else{
						s[i]=x+a+'0';
						a=0;
					}
				}
			}
		}	
	}
	cout <<s;
	return 0;
}
2024/5/29 17:34
加载中...