1. 此题用到了map<string,int>将输入的颜色(long long也存不下,只好作为string存入)的次数记录,看来默认一个没出现过的string对应的int是0。因此记次数的时候

if(mp[str])mp[str] += 1;//如果不是第一次出现,出现次数+1
else mp[str] = 1;//如果是第一次出现,记出现次数为1 

2. 用set<string>存所有输入的字符串,利用其去重和遍历的功能。

#include<cstdio>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<iostream>using namespace std;int main(){int row,col;scanf("%d %d",&col,&row);map<string,int> mp;set<string> st;string str;for(int i=0;i<row;i++){for(int j=0;j<col;j++){cin>>str;st.insert(str);if(mp[str])mp[str] += 1;//如果不是第一次出现,出现次数+1 else mp[str] = 1;//如果是第一次出现,记出现次数为1 }}int max = 0;string color; set<string>::iterator it = st.begin(); for(;it!=st.end();it++){if(max<mp[*it]){max = mp[*it];color = *it;}}cout<<color<<endl;return 0;
}

1054 The Dominant Color相关推荐

  1. 【PAT (Advanced Level) Practice】1054 The Dominant Color (20 分)

    1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ab ...

  2. PAT甲级1054 The Dominant Color:[C++题解]哈希表、水题

    文章目录 题目分析 题目链接 题目分析 来源:acwing AC代码 #include<bits/stdc++.h> using namespace std; const int N = ...

  3. PAT_(STL使用)map-1100 Mars Numbers (20分)-1054 The Dominant Color (20分)-1071-1022

    目录 1100 Mars Numbers (20分) 1054 The Dominant Color (20分) 1071 Speech Patterns (25分) 1022 Digital Lib ...

  4. 1054 The Dominant Color (20 分)_12行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Behind the scenes in the computer's memory, color is always talke ...

  5. 1054. The Dominant Color (20)

    时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Behind the scenes in the compute ...

  6. 1054 The Dominant Color (20 分)【难度: 简单 / 知识点: 思维】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805422639136768 因为数量多于一半,故排序后中间必为答案. # ...

  7. 【PAT甲级 找到出现次数过半的数字】1054 The Dominant Color (20 分) C++

    题目 思路 用数组模拟维护一个栈,栈内存储的数据有两个属性:数字.数量. 读取数字,如果数字已存在,相应位置上的数量+1 如果数字不存在,新建这个数字,size++,相应位置上的数量设置为1 题解 C ...

  8. Pat(Advanced Level)Practice--1054(The Dominant Color)

    Pat1054代码 题目描述: Behind the scenes in the computer's memory, color is always talked about as a series ...

  9. PAT甲级1054 map的使用

    题目 1054 The Dominant Color(20 分) Behind the scenes in the computer's memory, color is always talked ...

最新文章

  1. slowquery 慢查询
  2. python 周末大作业之2
  3. 0x5f3759df的数学原理
  4. Java命令行界面(第28部分):getopt4j
  5. 跟我学SpringMVC目录汇总贴、PDF下载、源码下载
  6. STL的算法补充笔记-1
  7. 2015.5.11 string与byte[]相互转换
  8. 一位大牛架构师的经验总结
  9. 【python、pyqt5】,打包出现的若干问题
  10. 大数据入门的知识体系,大数据学习路线
  11. python数据分析师网易云课堂_网易云课堂 数据分析(一)
  12. golang学习和校招经历
  13. gcc编译-m32、-mx32有什么区别
  14. AI-人工智能 easyAi开发技术
  15. 利用halcon识别汽车检具孔面积和孔间距
  16. Apache文件解析漏洞
  17. 知之者不如好之者 好之者不如乐之者
  18. 利用FPGA仿真软件modelsim仿真波形显示图片
  19. 【MATLAB编程实战】【例题实战】绘制曲面、曲线,求解偏导,计算极值点,二重积分,曲线积分,收敛性,麦克劳林展开式
  20. 2-6-RHEL6.5搭建vsftpd服务器案例分析与总结(Red Hat Enterprise Linux Server6.3)@树袋飘零...

热门文章

  1. webSocket详解
  2. JavaSE基础:Arrays工具类
  3. iOS开发 关于启动页和停留时间的设置
  4. NPOI 导出Excel
  5. 硬铺路、软筑墙:三星移动在中国的新路径
  6. nodejs -- promise的返回
  7. Mybatis【配置文件】就是这么简单
  8. Emoji表情图标在iOS与PHP之间通信及MySQL存储
  9. mac os下valgrind的安装
  10. JavaScript--练习1--99乘法表