uva 340

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=276

今天开始准备去uva做题,推荐一本书《》算法竞赛入门经典》这本书会对uva上部分题目进行讲解,很不错。 今天做了uva 340,后续会继续坚持刷题的。

 /* THE PROGRAM IS MADE BY SH */
/*---------------------------------------------------------------------------
 *       https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=276
 *       猜数字游戏的提示 
 *       Date  : 2015/6/8
----------------------------------------------------------------------------*/
#include
#include 
#include 
#define maxn 1010 
int main()
{
  int n,kase = 0;
  int a[maxn],b[maxn];
  while(scanf("%d",&n) == 1 && n){
      printf("Game %d:\n",++kase);
      for(int i = 0; i < n; ++i) scanf("%d",&a[i]);
      for(;;){
          int A = 0, B = 0;
          for(int i = 0; i < n; ++i){
              scanf("%d",&b[i]);
              if(a[i] == b[i]) A++;
          }
          if(b[0] == 0) break;
          for(int d = 1; d <= 9; ++d){
              int c1 = 0,c2 = 0;
              for(int i = 0; i < n; ++i){
                  if(a[i] == d) c1++;
                  if(b[i] == d) c2++;
               }
                  if(c1 < c2) B += c1; else B += c2;
          }
              printf("    (%d,%d)\n",A,B-A);
      }      
   }
  system("PAUSE");
  return 0;
}


你可能感兴趣的:(字符数组)