Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <cmath>
  6. #include <vector>
  7. #include <ctime>
  8. #include <cstdlib>
  9. #include <string>
  10.  
  11. using namespace std;
  12.  
  13. int main() {
  14.  
  15.     int n,ans=0;
  16.     cin >> n;
  17.     string s,s1;
  18.     srand(time(NULL));
  19.     vector<int>fir;
  20.     vector<int>sec;
  21.     while (1) {
  22.         for (int i = 0; i < n; i++) {
  23.             s.push_back(rand() % 2 + '0');
  24.         }
  25.         for (int i = 0; i < n; i++) {
  26.             printf("%c", s[i]);
  27.         }
  28.         printf("\n");
  29.         fflush(stdout);
  30.         cin >> ans;
  31.         if (ans == n) {
  32.             return 0;
  33.         }
  34.         if (ans == n / 2) break;
  35.         s.clear();
  36.     }
  37.     int i = 1;
  38.     s1.push_back(s[0]);
  39.     if (s[0] == '0')  s[0] += 1;
  40.     else  s[0] -= 1;
  41.     while (i<n) {
  42.  
  43.         if (s[i] == '0')  s[i] += 1;
  44.         else  s[i] -= 1;
  45.         for (int i = 0; i < n; i++) {
  46.             printf("%c", s[i]);
  47.         }
  48.         printf("\n");
  49.         fflush(stdout);
  50.         cin >> ans;
  51.         if (ans == n) {
  52.             return 0;
  53.         }
  54.         if (ans == 0) {
  55.             if (s[i] == '0')  s[i] += 1;
  56.             else  s[i] -= 1;
  57.             s1.push_back(s[i]);
  58.         }
  59.         if (ans == n / 2) {
  60.             s1.push_back(s[i]);
  61.             if (s[i] == '0')  s[i] += 1;
  62.             else  s[i] -= 1;
  63.         }
  64.         i++;
  65.     }
  66.     for (int i = 0; i < n; i++) {
  67.         printf("%c", s1[i]);
  68.     }
  69.     printf("\n");
  70.     fflush(stdout);
  71.     cin >> ans;
  72.     if (ans == n) return 0;
  73.     else {
  74.         for (int i = 0; i < n; i++) {
  75.             if (s1[i] == '0')  s1[i] += 1;
  76.             else  s1[i] -= 1;
  77.             printf("%c", s1[i]);
  78.         }
  79.     }
  80.     printf("\n");
  81.     fflush(stdout);
  82.     cin >> ans;
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement