1400*C. Given Length and Sum of Digits...(贪心)

Problem - 489C - Codeforces

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
int m,s,a[110];
signed main(){
	scanf("%d%d",&m,&s);
	if(s>m*9) puts("-1 -1");
	else if(s==0&&m>1) puts("-1 -1");
	else if(s==0&&m==1) puts("0 0");
	else{
		int t=s;
		t-=1;
		a[1]=1;
		for(int i=m;i>=1;i--){
			if(t>=9){
				a[i]+=9;
				t-=9;
			}
			else{
				a[i]+=t;
				break;
			}
		}
		for(int i=1;i<=m;i++) cout<<a[i];
		cout<<" ";
		t=s;
		memset(a,0,sizeof a);
		for(int i=1;i<=m;i++){
			if(t>=9){
				a[i]+=9;
				t-=9;
			}
			else{
				a[i]+=t;
				break;
			}
		}
		for(int i=1;i<=m;i++) cout<<a[i];
	}
	return 0;
}
相关推荐
2401_838472514 分钟前
C++中的装饰器模式实战
开发语言·c++·算法
沐知全栈开发11 分钟前
PHP 数组
开发语言
白中白1213811 分钟前
算法题-06
算法
雨季66614 分钟前
Flutter 三端应用实战:OpenHarmony “心流之泉”——在碎片洪流中,为你筑一眼专注的清泉
开发语言·前端·flutter·交互
YMWM_26 分钟前
python3中类的__call__()方法介绍
开发语言·python
爱学习的阿磊27 分钟前
C++与Qt图形开发
开发语言·c++·算法
历程里程碑31 分钟前
Linux 16 环境变量
linux·运维·服务器·开发语言·数据库·c++·笔记
二年级程序员31 分钟前
C 语言文件操作
c语言
爱敲代码的TOM33 分钟前
基础算法技巧总结2(算法技巧零碎点,基础数据结构,数论模板)
数据结构·算法
小莞尔33 分钟前
【51单片机】【protues仿真】 基于51单片机波形发生器系统
c语言·单片机·嵌入式硬件·物联网·51单片机