codeforces B. The number on the board

来源:互联网 发布:淘宝网开放平台 编辑:程序博客网 时间:2024/06/06 19:32

点这里

一开始题意理解错了。。。

就是要求使一个数k的每一位数的总和小于n

#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;char x[100005];int  t[100005];bool cmp(int a,int b){    return a>b;}int main(){    int n;    while(~scanf("%d",&n))    {        getchar();        gets(x);        int len=strlen(x);        int ans=0,c=0;        for(int i=0; i<len; i++)        {            t[i]=x[i]-'0';            ans+=t[i];        }        if(ans>=n)            cout<<0<<endl;        else        {            sort(t,t+len);            while(ans<n)            {                ans+=(9-t[c]);                  c++;            }            cout<<c<<endl;        }    }    return 0;}


原创粉丝点击