CF 277.5 C.Given Length and Sum of Digits.. 构造

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
int a[1000];
int main()
{
    int m,s;
    cin>>m>>s;
    if(m==1&&s==0)
    {
        cout<<"0 0"<<endl;
        return 0;
    }
    if(s==0)
    {
        cout<<"-1 -1"<<endl;
        return 0;
    }
    if(s>9*m)
    {
        cout<<"-1 -1"<<endl;
        return 0;
    }
    int t=s-1;//精湛的-1 屌不屌?
    for(int i=0;i<m;i++)
    {
        int r=min(t,9);
        a[i]=r;
        t-=r;
    }
    a[m-1]++;
    for(int i=m-1;i>=0;i--)
        cout<<a[i];
    cout<<" ";
    t=s;
    for(int i=0;i<m;i++)
    {
        int r=min(9,t);
        cout<<r;
        t-=r;
    }
    cout<<endl;
    return 0;
}

 

posted @ 2014-11-18 14:54  qscqesze  阅读(306)  评论(0编辑  收藏  举报