Advertisement
RoshHoul

digit (task1)

Sep 29th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. // Task1.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <stack>
  7. #include <sstream>
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13.     int a, b, p1, p2;
  14.     stringstream sequence;
  15.     stringstream result;
  16.  
  17.     cin >> a >> b >> p1 >> p2;
  18.  
  19.     for (int i = a; i <= b; i++) {
  20.         sequence << i;
  21.     }
  22.  
  23.     for (int i = 0; i < sequence.str().length(); i++) {
  24.         int x = sequence.str()[i] - '0';
  25.  
  26.         if ((x % p1 != 0) && (x % p2 != 0)) {
  27.             result << x;
  28.         }
  29.         else {
  30.             continue;
  31.         }
  32.     }
  33.  
  34.     cout << result.str().length();
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement