Codeforces Round #277.5 (Div. 2) C
来源:互联网 发布:java鱼雷多重 编辑:程序博客网 时间:2024/05/16 01:56
题目: http://codeforces.com/contest/489/problem/C
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).
2 15
69 96
3 0
-1 -1
#include<stdio.h>#include<iostream>#include<math.h>#include<stdlib.h>#include<ctype.h>#include<algorithm>#include<vector>#include<string.h>#include<queue>#include<stack>#include<set>#include<map>#include<sstream>#include<time.h>#include<malloc.h>using namespace std;int n,m;int a[110];int main (){ while (scanf("%d %d",&n,&m)!=EOF) { if ( m == 0 ) { if ( n == 1) printf("0 0\n"); else printf("-1 -1\n"); } else if ( n*9 < m) printf("-1 -1\n"); else { { memset(a,0,sizeof(a)); a[n-1] = 1; int ans = m-1; for(int i=0 ;ans && i<n;i++) { while (ans != 0 && a[i]<9) { ans--; a[i]++; } } for(int i=n-1;i>=0;i--) printf("%d",a[i]); printf(" "); } { memset(a,0,sizeof(a)); a[0]= 1 ; int ans = m-1; for(int i=0;ans && i<n;i++) { while (ans !=0 && a[i]<9) { ans --; a[i]++; } } for(int i=0 ;i<n;i++) printf("%d",a[i]); printf("\n"); } } } return 0;}
- Codeforces Round #277.5 (Div. 2)-C
- Codeforces Round #277.5 (Div. 2) C
- Codeforces Round #277.5 (Div. 2) C
- Codeforces Round #277.5 (Div. 2)(C题)
- 【codeforces】Codeforces Round #370 (Div. 2) C
- Codeforces Round #277.5 (Div. 2)
- Codeforces Round #277.5 (Div. 2)
- Codeforces Round #277.5 (Div. 2)
- Codeforces Round #277.5 (Div. 2)
- Codeforces Round #277.5 (Div. 2)
- Codeforces Round #277.5 (Div. 2) A B C D
- Codeforces Round #105 (Div. 2) C
- Codeforces Round 134 div 2 C题
- Codeforces Round #137 (Div. 2), problem: (C)
- Codeforces Round #153 (Div. 2) C题
- Codeforces Round #158 (Div. 2) C题
- Codeforces Round #162 (Div. 2) C
- Codeforces Round #166 (Div. 2) c. Secret
- Android ViewGroup事件分发机制
- 利用Python进行数据分析--时间序列
- Android 快速开发系列 ORMLite 框架最佳实践
- spring3 的控制器单例与多例
- 手机号码和电话号码的正则表达式
- Codeforces Round #277.5 (Div. 2) C
- VMware CentOS LVM磁盘扩容
- C++文件读写
- Android AsyncTask 源码解析
- 组合优于继承
- Android Handler 异步消息处理机制的妙用 创建强大的图片加载类
- Android 智能问答机器人的实现
- Android 异步消息处理机制 让你深入理解 Looper、Handler、Message三者关系
- 矩阵转圈输出数字