Codeforces 489C Given Length and Sum of Digits...

知识点:模拟、贪心、分支语句

题目

You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.

输入

The single line of the input contains a pair of integers m, s (1 ≤ m ≤ 100, 0 ≤ s ≤ 900) — the length and the sum of the digits of the required numbers.

输出

In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers “-1 -1” (without the quotes).

样例

输入1

2 15

输出1

69 96

输入2

3 0

输出2

-1 -1

题意

求指定位数的最小和最大的各位数之和等于指定数字的两个数字。

思路

(记得写思路)
实现思路见代码。

代码

//克服WA难,终得AC
#include"bits/stdc++.h"
#define ll long long
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define reb(i,a,b) for(ll i=a;i<=b;i++)
#define rev(i,a,b) for(ll i=a-1;i>=b;i--)
#define red(i,a,b) for(ll i=a;i>=b;i--)
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

ll m,s;
ll digit[110];

int main() {
   
  scanf("%lld%lld",&m,&s);
  ll t=s;
  rev(i,m,0) {
   
    if(t>10) {
   
      digit[i]=9;
      t-=9;
    } else if(t>1) {
   
      digit[i]=t-1;
      t=1;
    } else
      digit[i]=0;
  }
  if(t&&digit[0]<9) {
   
    digit[0]+=t;
    t=0;
  }
  if(t||digit[0]==0&&m!=1) goto x;
  rep(i,0,m)
  cout<<digit[i];
  cout<<" ";
  t=s;
  rep(i,0,m) {
   
    if(t>9) {
   
      digit[i]=9;
      t-=9;
    } else if(t>0) {
   
      digit[i]=t;
      t=0;
    } else digit[i]=0;
  }
  rep(i,0,m) cout<<digit[i];
  cout<<endl;
  return 0;
x:
  cout<<"-1 -1"<<endl;
  return 0;
}
全部评论

相关推荐

07-25 11:12
重庆大学 C++
既然这么缺人,为什么挂我呢
希望被offer砸中...:其实不缺人
点赞 评论 收藏
分享
机械打工仔:不管啥专业,找工作改简历的第一课先把你那排版改了,简历上不要写个人简历四个字,找你要简历的谁不知道这个是简历?而且还占那么多空间,直接把自己名字和基础信息写上面,整体字体大一些。 还有这种经典两页简历一页大空白,导出PDF的时候多了一页几乎全是白的你自己看着不难受吗随手的事为啥不能改掉呢,这是态度问题,你试想一下你是HR你打开简历看到格式都没调整过会是什么感受?你自己都不重视你的简历,HR更不会在意。 然后内容你那个做两年咖啡就别往里写了,简历在精不在多,你在往你的简历里打字的时候就要想好这东西对你要找的工作有没有帮助。自我评价写一行就行了,不如给专业技能单开一栏。核心课程均分90这个真别写了,把你上过的有用的专业课列出来也行。有很多地方废话很多的精炼一下,比如你校内项目第一个写的那些,全然没有重点。 好好修改一下,我看你内容也挺优秀的,别被一个随便做的简历耽误了,我一个同专业的打工人看了都揪心更别说一天看几百份简历的HR
听劝,我这个简历该怎么改...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务