Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Mar 31st, 2020 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3. #include <list>
  4. #include <sstream>
  5.  
  6. using namespace std;
  7.  
  8. //9, 7, 72
  9. int main() {
  10.     string input;
  11.     getline(cin, input);
  12.     int startNumber = 0;
  13.     int d = 0;
  14.     int numberToSearch = 0;
  15.     int count = 0;
  16.     for (int i = 0; i < input.size(); ++i) {
  17.  
  18.         string currentNumber = "";
  19.         for (int j = i; j < input.size(); ++j) {
  20.             if (isdigit(input.at(j))) {
  21.                 currentNumber += input.at(j);
  22.             } else {
  23.                 i = j;
  24.                 break;
  25.             }
  26.         }
  27.         if (!currentNumber.empty()) {
  28.             if (count == 0) {
  29.                 startNumber = stoi(currentNumber);
  30.             } else if (count == 1) {
  31.                 d = stoi(currentNumber);
  32.             } else if (count == 2) {
  33.                 numberToSearch = stoi(currentNumber);
  34.             }
  35.             count++;
  36.         }
  37.     }
  38.     string saveFirst = to_string(startNumber);
  39.     int m = 0;
  40.     int n = 1;
  41.     int sum = 0;
  42.     while (startNumber < numberToSearch) {
  43.         if (sum == 0) {
  44.             sum = startNumber + startNumber + d;
  45.             startNumber += d;
  46.         } else {
  47.             int saveLast = sum;
  48.             startNumber += d;
  49.             sum = startNumber + saveLast;
  50.         }
  51.         string numberToString = to_string(startNumber);
  52.         for (int i = 0; i < numberToString.size(); ++i) {
  53.             for (int j = 0; j < saveFirst.size(); ++j) {
  54.                 if (numberToString.at(i) == saveFirst.at(j)) {
  55.                     m++;
  56.                 }
  57.             }
  58.         }
  59.         n++;
  60.     }
  61.     sum -= startNumber;
  62.     cout << "n = " << n << ", S = " << sum << ", m = " << m << endl;
  63.     return 0;
  64. }
  65.  
  66. // 10
  67. // 22 + 4
  68. // 26 + 4
  69. // 30 + 4
  70. // 34 + 4
  71. // 38 + 4
  72. // 42 + 4
  73. // 46 + 4
  74. // 50 + 4
  75. // 54 + 4
  76. //n = 9?? Примера е грешен...?
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top