fork download
  1. #include<cstdio>
  2. #include<iostream>
  3. #include<algorithm>
  4. #include<cmath>
  5. #include<cstdlib>
  6. #include<queue>
  7. #include<map>
  8. #include<set>
  9. #include<string>
  10. #include<sstream>
  11. #include<climits>
  12. #include<vector>
  13. #include<cstring>
  14. #include<stack>
  15.  
  16. using namespace std;
  17.  
  18. #define REP(i,s,n) for (int i=(s),_n=(n);i<=_n;i++)
  19. #define FOR(i,s,n) for (int i=(s),_n=(n);i<_n;i++)
  20. #define REPD(i,e,s) for (int i=(e),_s=(s);i>=_s;i--)
  21. #define tr(container, it) \
  22. for (typeof(container.begin()) it=container.begin(); it!=container.end();it++)
  23. #define PB push_back
  24.  
  25. typedef long long LL;
  26. typedef vector<int> VI;
  27. typedef pair<int,int> PI;
  28.  
  29. long long int ans=0;
  30.  
  31. int main() {
  32. long long int a,b;
  33. cin >>a >> b;
  34. ans=a;
  35. long long int cpy=a,t=0;
  36. while(b>0)
  37. {
  38. if( a%10 ==9)
  39. {
  40. a/=10;
  41. b/=10;
  42. }
  43. else
  44. {
  45. if(a%10+1 <=b)
  46. {
  47.  
  48. cpy-=(a%10+1)* (long long int) (pow((long long int)10,t));
  49. b-=a%10+1;
  50. a-=a%10+1;
  51. a/=10;
  52. b/=10;
  53. }
  54. else
  55. break;
  56. }
  57. t+=1;
  58. }
  59. cout<<cpy<<endl;
  60. return 0;
  61. }
  62.  
Success #stdin #stdout 0.01s 2728KB
stdin
29287101 301
stdout
29286999