Guest User

Untitled

a guest
Jul 15th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <sstream>
  5. using namespace std;
  6.  
  7. void keep_window_open();
  8.  
  9.  
  10. int main()  {
  11.  
  12.     try {
  13.  
  14.         int i = 0;
  15.         int j = 0;
  16.  
  17.         vector<int> comp(4);
  18.         vector<int> user(4);
  19.         vector<int> results(4);
  20.         char tmp[4];
  21.                
  22.         comp[0] = 1;
  23.         comp[1] = 2;
  24.         comp[2] = 3;
  25.         comp[3] = 4;
  26.  
  27.         cout << "1a2a3a\n";
  28.         cin >> tmp;
  29.         for (int i = 0; i < user.size(); i++) user[i] = static_cast<int> (tmp[i] - 0x30);
  30.        
  31.                
  32.         cout << user.size() << " ";
  33.  
  34.         for (i = 0; i < user.size(); i++) cout << user[i] << " ";
  35.         cout << endl;
  36.  
  37.         int cow = 0, bull = 0;
  38.        
  39.         for (i = 0; i < user.size(); i++)   {
  40.             if (comp[i] == user[i]) {
  41.                 bull++;
  42.                 results[i] = 2;
  43.             }
  44.         }
  45.  
  46.         for (i = 0; i < user.size(); i++)   {
  47.             for (j = 0; j < comp.size(); j++)   {
  48.                 if (j != i && results[i] == 0) {
  49.                     cow++;
  50.                     results[i] = 1;
  51.                 }
  52.             }
  53.         }
  54.  
  55.         cout << "\t" << bull << "\t" << cow;
  56.  
  57.  
  58.         keep_window_open();
  59.         return 0;
  60.  
  61.     } catch (exception& e)  {
  62.         cerr << "Error: " << e.what() << "\n";
  63.         keep_window_open();
  64.         return 1;
  65.     }
  66.  
  67. }
  68.    
  69.  
  70.  
  71. void keep_window_open()
  72. {
  73.     // clear buffer
  74.     fflush(stdin);
  75.     printf("\nPlease enter a character to exit\n");
  76.     char ch;
  77.     ch = getchar();
  78.     return;
  79. }
Add Comment
Please, Sign In to add comment