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;
}
相关推荐
维吉斯蔡5 小时前
【VS Code / Cursor】文件夹右键快捷打开与文件类型自动关联
开发语言·程序人生·学习方法
luj_17687 小时前
星火科技助力边远地区防病攻坚
c语言·开发语言·c++·经验分享·算法
always_TT8 小时前
【Python 日志记录:logging 模块入门】
开发语言·python·php
画面无声8 小时前
STM32的SPI通信原理与练习记录
c语言·stm32·单片机·嵌入式硬件·学习
xcLeigh8 小时前
Go入门:变量声明的五种方式详解
java·开发语言·golang
weixin_456808388 小时前
【沁恒蓝牙开发】IAP升级流程
c语言·单片机·嵌入式硬件
zmzb01038 小时前
C++课后习题训练记录Day175
开发语言·c++
脱胎换骨-军哥9 小时前
C++ 代码规范与格式化指南
开发语言·c++·代码规范
木木子229 小时前
# 鸿蒙 ArkTS 实战:秒表 Stopwatch(示例 5)
数据结构·华为·list·harmonyos
枕星而眠10 小时前
C++ STL Map容器完全指南:从有序红黑树到无序哈希表
java·开发语言