Advertisement
dimyasha

Арифметическая прогрессия 2

Feb 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. #include <math.h>
  2. #include <iomanip>
  3. #include <iostream>
  4. #include <string>
  5. //#include <stack>
  6. #include <stdio.h>
  7. //#include <queue>
  8. //#include <set>
  9. //#include <time.h>
  10. #include <vector>
  11. #define pause system("pause")
  12. using namespace std;
  13. //setlocale(LC_ALL, "Russian");
  14. //printf("%d ", x);
  15. //scanf_s("%d", &x);
  16.  
  17. #include <ctime>
  18. unsigned int start_time;
  19. void begin_c() {
  20.     start_time = clock(); // начальное время
  21. }
  22. void end_c() {
  23.     unsigned int end_time = clock(); // конечное время
  24.     unsigned int search_time = end_time - start_time; // искомое время
  25.     cout << "Runtime = " << (double)search_time / 1000 << " seconds" << endl;
  26. }
  27.  
  28. vector <int> a;
  29. vector <int> help;
  30.  
  31. void mergerSort(int l, int r) {
  32.     if (l < r) {
  33.         int c = (l + r) / 2;
  34.         mergerSort(l, c);
  35.         mergerSort(c + 1, r);
  36.         int i = l;
  37.         int j = c + 1;
  38.         int k = l;
  39.         while (i <= c && j <= r) {
  40.             if (a[i] <= a[j]) {
  41.                 help[k] = a[i];
  42.                 i++;
  43.                 k++;
  44.             }
  45.             else {
  46.                 help[k] = a[j];
  47.                 j++;
  48.                 k++;
  49.             }
  50.         }
  51.         while (i<=c) {
  52.             help[k] = a[i];
  53.             k++;
  54.             i++;
  55.         }
  56.         while (j <= r) {
  57.             help[k] = a[j];
  58.             k++;
  59.             j++;
  60.         }
  61.         }
  62. }
  63.  
  64. int main() {
  65.     string s;
  66.     getline(cin, s);
  67.     int num = 0;
  68.     int n = 0;
  69.     for (int i = 0; i < s.length(); i++) {
  70.         if (i == s.length()-1) {
  71.             num *= 10;
  72.             num += s[i] - '0';
  73.             a.push_back(num);
  74.             n++;
  75.         }
  76.         else {
  77.             if (s[i] == ' ') {
  78.                 a.push_back(num);
  79.                 num = 0;
  80.                 n++;
  81.             }
  82.             else {
  83.                 num *= 10;
  84.                 num += s[i] - '0';
  85.             }
  86.         }
  87.     }
  88.     help.resize(a.size());
  89.     mergerSort(0, n - 1);
  90.     for (int i = 0; i < n; i++) printf("%d ", a[i]);
  91.     cout << endl;
  92.     int d = 0;
  93.     d = a[1] - a[0];
  94.     for (int i = 2; i < n; i++) {
  95.         int del = a[i] - a[i - 1];
  96.         if (del != d) {
  97.             cout << "No" << endl;
  98.             pause;
  99.             return 0;
  100.         }
  101.     }
  102.     cout << "Yes" << endl;
  103.     pause;
  104.     return 0;
  105.  
  106.     pause;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement