zoukankan      html  css  js  c++  java
  • UVA-340 Master-Mind Hints

     1 #include <iostream>
     2 #include <stdlib.h>
     3 #include <string>
     4 #include <vector>
     5 #include <algorithm>
     6 #include <string.h>
     7 #include <stack>
     8 #include <unordered_map>
     9 #include <math.h>
    10 
    11 using namespace std;
    12 
    13 int main()
    14 {
    15     int listLength;
    16     int tol = 1;
    17     while(cin >> listLength)
    18     {
    19         if(listLength==0)
    20             break;
    21 
    22         vector<int> correctList;
    23         vector<int> correctHash (10,0);
    24         for(int i = 0; i < listLength; i ++)
    25         {
    26             int tmp;
    27             cin >> tmp;
    28             correctList.emplace_back(tmp);
    29             correctHash[tmp] ++;
    30         }
    31 
    32         cout << "Game " << tol++ << ":" << endl;
    33         while(1)
    34         {
    35             vector<int> guessHash (10,0);
    36             int A = 0,B = 0;
    37             int flag = 0;
    38             for(int i = 0; i < listLength; i ++)
    39             {
    40                 int tmp;
    41                 cin >> tmp;
    42                 if(tmp==0)
    43                 {
    44                     flag = 1;
    45                 }
    46                 else
    47                 {
    48                     if(tmp==correctList[i])
    49                         A ++;
    50                     guessHash[tmp] ++;
    51                 }
    52             }
    53             if(flag)
    54                 break;
    55             for(int i = 1; i <= 9; i ++)
    56             {
    57                 B += min(correctHash[i],guessHash[i]);
    58             }
    59             cout << "    (" << A << "," << B-A << ")" << endl;
    60         }
    61     }
    62     return 0;
    63 }
  • 相关阅读:
    32 最小子串覆盖
    31 数组划分
    29 交叉字符串
    动态规划
    18 带重复元素的子集
    17 子集
    16 带重复元素的排列
    23.二叉树的后续遍历序列
    J.U.C-其他组件
    21.Longest Palindromic Substring(最长回文子串)
  • 原文地址:https://www.cnblogs.com/Asurudo/p/9591155.html
Copyright © 2011-2022 走看看