PAT:1054. The Dominant Color (20) AC(map法)

#include<stdio.h>
#include<map>
using namespace std;
const int MAX=0x3fffffff;
int main()
{
  int m,n;
  map<int,int> count;        //数字与出现次数的map映射
  scanf("%d%d",&m,&n);
  for(int i=0 ; i<n ; ++i)
  {
    for(int j=0 ; j<m ; ++j)
    {
      int tmp;
      scanf("%d",&tmp);
      if(count.find(tmp)!=count.end())  //存在,次数+1
        ++count[tmp];
      else                //不存在,次数设为1
        count[tmp]=1;
    }
  }
  int ans=-1,MAXtmp=-1;
  for(map<int,int>::iterator it=count.begin() ; it!=count.end() ; ++it)
  {
    if(it->second>MAXtmp)          //【skill】map映射的第一第二位置的使用
    {
      ans=it->first;
      MAXtmp=it->second;
    }
  }
  printf("%d\n",ans);
  return 0;
}
时间: 2024-11-03 21:54:08

PAT:1054. The Dominant Color (20) AC(map法)的相关文章

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

#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",&

pat 1054 The Dominant Color(20 分)

1054 The Dominant Color(20 分) Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional area is called the dominant color. A str

PAT Advanced 1054 The Dominant Color (20分)

Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional area is called the dominant color. A strictly dominant color takes mor

1054. The Dominant Color (20)

时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional ar

PAT (Advanced Level) 1054. The Dominant Color (20)

简单题 #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<queue> #include<algorithm> using namespace std; int a[500000]; int n,m; int main() { scanf("%d%d",&n,&m); for(int i=0;i&

PAT 甲级 1054 The Dominant Color (20 分)

1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional area is called the dominant color. A st

A1054. The Dominant Color (20)

Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional area is called the dominant color. A strictly dominant color takes mor

1054. The Dominant Color

Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional area is called the dominant color. A strictly dominant color takes mor

PAT:1027. 打印沙漏(20) AC

#include int main() { int n; char xing; scanf("%d %c",&n,&xing); int num=1,i=1; while(1) { num = num + 2 * (i + 2); //一开始就超出,不改变i if(num > n) break; i += 2; } int MAX=i; for(int k=0 ; kPAT:1027. 打印沙漏(20) AC