看题可以容易知道给定的数得是10001的倍数
n 必须用字符串储存,然后模拟减去10001 再除10,继续重复这个步骤
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
using namespace std;
const int maxn = 10000000 + 7;
char s[maxn];
int a[maxn];
void solve()
{
int n = strlen(s);
for(int i = 0; i < n; i++)
{
a[i] = s[i] - '0';
}
for(int i = n - 1; i - 4 >= 0; i--)
{
int j = i - 4;
a[j] -= a[i];
a[i] -= a[i];
while(a[j] < 0 && j < n)
{
a[j] += 10;
a[j - 1]--;
j++;
}
}**HDU 5832 A water problem**
for(int i = 0; i < n; i++)
{
if(a[i] != 0)
{
cout << "NO" << endl;
return ;
}
}
cout << "YES" << endl;
}
int main()
{
int cases = 0;
while(~scanf("%s", s))
{
printf("Case #%d: ", ++cases);
solve();
memset(a, 0, sizeof(a));
memset(s, 0, sizeof(s));
}
return 0;
}