193030

2013 01. A Задача с остатък(много цифри)

Mar 31st, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <string.h>
  4. #include <cstdlib>
  5. #include <sstream>      // std::stringstream
  6. #include <cstdio>
  7. #include <algorithm> // Bigint
  8.  
  9. using namespace std;
  10.  
  11.  
  12.  
  13. string input = " ";
  14.  
  15. long sstoi(const char *s) // custom stoi function
  16. {
  17.     long i;
  18.     i = 0;
  19.     while(*s >= '0' && *s <= '9')
  20.     {
  21.         i = i * 10 + (*s - '0');
  22.         s++;
  23.     }
  24.     return i;
  25. }
  26.  
  27.  
  28. int mod(string num, int a)
  29. {
  30.     // Initialize result
  31.     int res = 0;
  32.  
  33.     // One by one process all digits of 'num'
  34.     for (int i = 0; i < num.length(); i++)
  35.         res = (res*10 + (int)num[i] - '0') %a;
  36.  
  37.     return res;
  38. }
  39.  
  40. int main() {
  41.  
  42.     int k = 0;
  43.     cin >> k;
  44.     string newString;
  45.     uint64_t  numbers[k] = {};
  46.     int output[k] = {};
  47.     cin.sync();
  48.  
  49.     for(int i =0; i<k; i++)
  50.     {
  51.  
  52.         getline(cin, input);
  53.         newString = input.erase(input.size() - 1);
  54.         //numbers [i] = atoi(newString.c_str()); // S tova ne raboti
  55.        //  numbers[i] = sstoi (input.c_str());
  56.  
  57.        output[i] = mod(newString,3);
  58.  
  59.     }
  60.  
  61.  
  62.     for(int i =0; i<k; i++)
  63.     {
  64.     if(output[i]==0)
  65.         cout << "Yes" <<endl;
  66.     else
  67.         cout << output[i] << endl;
  68.     }
  69.  
  70.  
  71.  
  72. }
Add Comment
Please, Sign In to add comment