码迷,mamicode.com
首页 > 其他好文 > 详细

PAT:1054. The Dominant Color (20) AC(抓住最多的特点,处理不同和相同的情况,留下剩余的答案)

时间:2015-03-10 23:03:35      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

#include<stdio.h>

int main()
{
  int m,n,ans,tmp,times=0;
  scanf("%d%d",&m,&n);
  for(int i=0 ; i<n ; ++i)    //【思维】题目找出现次数最多的一个,找到不同的,次数减少1,减少到0就换成输入的数字。找到相同的数字,次数+1.最后剩下的一定就是答案
  {
    for(int j=0 ; j<m ; ++j)
    {
      scanf("%d",&tmp);
      if(tmp==ans)
        ++times;
      else
      {
        if(times==0)
        {
          ans=tmp;
          times=1;
        }
        else
          --times;
      }
    }
  }

  printf("%d",ans);
  return 0;
}

PAT:1054. The Dominant Color (20) AC(抓住最多的特点,处理不同和相同的情况,留下剩余的答案)

标签:

原文地址:http://www.cnblogs.com/Evence/p/4328638.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!