zoukankan      html  css  js  c++  java
  • [原创]我的北大ACM POJ 1013解答

    我的北大ACM POJ 1013解答
    又一个水题,居然还贡献了3次WA。。。

    Source Code

    Problem: 1013
    User: absolute
    Memory: 204K
    Time: 0MS
    Language: C++
    Result: Accepted
    • Source Code
    • #include <stdio.h>
      #include <string>
      void POJ1013();
      int main()
      {
      POJ1013();
      return 0;
      }
      void POJ1013()
      {
      int i,k,casen;
      scanf("%d",&casen);
      while(casen>0)
      {
      casen--;
      bool real[12]={0};
      int heavy[12]={0};
      int light[12]={0};
      for(k=0;k<3;k++)
      {
      char input[3][8]={0};
      int j;
      scanf("%s %s %s",&input[0],&input[1],&input[2]);
      //平衡则放入真数组,表示这次称的都是真币
      if(strcmp(input[2],"even")==0)
      {
      j=0;
      while(input[0][j]!='\0')
      {
      real[input[0][j]-'A']=true;
      real[input[1][j]-'A']=true;
      j++;
      }
      }
      //右边起来,左边怀疑为重,右边怀疑为轻
      else if(strcmp(input[2],"up")==0)
      {
      j=0;
      while(input[0][j]!='\0')
      {
      heavy[input[0][j]-'A']++;
      light[input[1][j]-'A']++;
      j++;
      }
      }
      //右边下降,左边怀疑为轻,右边为重
      else if(strcmp(input[2],"down")==0)
      {
      j=0;
      while(input[0][j]!='\0')
      {
      light[input[0][j]-'A']++;
      heavy[input[1][j]-'A']++;
      j++;
      }

      }
      }
      char maxnum='A';
      int heavyorlight=0;
      //假币必然是不在真数组中,而且它必然只能在重数组和轻数组之一出现,而不能同时出现
      //但是有可能被怀疑的只称过一次,所以必须选出被怀疑最多次的那个
      for(i='A';i<'M';i++)
      {
      if(real[i-'A'])
      continue;
      int temp=0;
      if(light[i-'A']>0&&heavy[i-'A']==0)
      {
      if(heavyorlight==1)
      temp=light[maxnum-'A'];
      else if(heavyorlight==2)
      temp=heavy[maxnum-'A'];
      if(light[i-'A']>temp)
      {
      heavyorlight=1;
      maxnum=i;
      }
      continue;
      }
      if(light[i-'A']==0&&heavy[i-'A']>0)
      {
      if(heavyorlight==1)
      temp=light[maxnum-'A'];
      else if(heavyorlight==2)
      temp=heavy[maxnum-'A'];
      if(heavy[i-'A']>temp)
      {
      heavyorlight=2;
      maxnum=i;
      }
      continue;
      }
      }
      if(heavyorlight==1)
      printf("%c is the counterfeit coin and it is light.\n",maxnum);
      else
      printf("%c is the counterfeit coin and it is heavy.\n",maxnum);
      }
      }

  • 相关阅读:
    配置PyCharm(背景色+字体大小+解释器选择)
    面向对象的三大特性(封装、继承、多态)
    hashlib模块
    logging模块
    Mac OSX系统、Linux、Windows命令行教程
    Python2和Python3的一些语法区别
    python——内置函数和lambda匿名函数
    python——异常处理
    SVN
    实体框架Entity Framework 4.1快速入门
  • 原文地址:https://www.cnblogs.com/absolute8511/p/1649593.html
Copyright © 2011-2022 走看看