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;
}
相关推荐
leo__52011 分钟前
IEC 104 协议 C 语言实现
c语言·数据库
CHANG_THE_WORLD11 分钟前
python 批量终止进程exe
开发语言·python
古城小栈13 分钟前
从 cargo-whero 库中,找到提升 rust 的契机
开发语言·后端·rust
学涯乐码堂主36 分钟前
有趣的“打擂台算法”
c++·算法·青少年编程·gesp
切糕师学AI1 小时前
环形缓冲区(Ring Buffer / Circular Buffer)详解:原理、优势、应用与高性能实现
数据结构·环形缓冲区
Tutankaaa1 小时前
知识竞赛题库设计全攻略
人工智能·算法
WolfGang0073212 小时前
代码随想录算法训练营 Day50 | 图论 part08
数据结构·算法·图论
Gary Studio2 小时前
安卓HAL C++基础-智能指针
开发语言·c++
啧不应该啊2 小时前
Day1 Python 与 C 的类型区别
c语言·开发语言
cen__y2 小时前
Linux07(信号01)
linux·运维·服务器·c语言·开发语言