AlenAntonelli

algo

Jul 9th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int a, b;
  10.     cin>>a>>b;
  11.    
  12.     int c = 0;
  13.     while (a>0 && b>0)
  14.     {
  15.         if (a > b)
  16.             swap(a,b);
  17.        
  18.         a++, b-=2;
  19.         c++;
  20.     }
  21.     cout<<c;
  22.    
  23.     return 0;
  24. }
  25.  
  26. #include <iostream>
  27. #include <vector>
  28. #include <algorithm>
  29. #include <math.h>
  30. using namespace std;
  31.  
  32. int n;
  33.  
  34. int val (string s)
  35. {
  36.     int num=0, m=(n-2);
  37.    
  38.     for(int i=0; i<=m; i++)
  39.         num += (s[i]-'0') * pow(10,m-i);
  40.    
  41.     return num;
  42. }
  43.  
  44. int main()
  45. {
  46.     string s, g;
  47.     cin>>s;
  48.    
  49.     n = s.size();
  50.     bool no=true;
  51.    
  52.     for(int i=0; i<n && no ; i++)
  53.     {
  54.         g.clear();
  55.         for(int j=0; j<n; j++)
  56.             if (j!=i)
  57.                 g+=s[j];
  58.        
  59.         if ( val(g)%8==0 )
  60.         {
  61.             cout<<"YES"<<endl<<g;
  62.             no = false;
  63.         }
  64.     }
  65.     if (no)
  66.         cout<<"NO";
  67.    
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment