1054 The Dominant Color
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相关推荐
- 【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 ...
- PAT甲级1054 The Dominant Color:[C++题解]哈希表、水题
文章目录 题目分析 题目链接 题目分析 来源:acwing AC代码 #include<bits/stdc++.h> using namespace std; const int N = ...
- 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 ...
- 1054 The Dominant Color (20 分)_12行代码AC
立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Behind the scenes in the computer's memory, color is always talke ...
- 1054. The Dominant Color (20)
时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Behind the scenes in the compute ...
- 1054 The Dominant Color (20 分)【难度: 简单 / 知识点: 思维】
https://pintia.cn/problem-sets/994805342720868352/problems/994805422639136768 因为数量多于一半,故排序后中间必为答案. # ...
- 【PAT甲级 找到出现次数过半的数字】1054 The Dominant Color (20 分) C++
题目 思路 用数组模拟维护一个栈,栈内存储的数据有两个属性:数字.数量. 读取数字,如果数字已存在,相应位置上的数量+1 如果数字不存在,新建这个数字,size++,相应位置上的数量设置为1 题解 C ...
- 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 ...
- PAT甲级1054 map的使用
题目 1054 The Dominant Color(20 分) Behind the scenes in the computer's memory, color is always talked ...
最新文章
- slowquery 慢查询
- python 周末大作业之2
- 0x5f3759df的数学原理
- Java命令行界面(第28部分):getopt4j
- 跟我学SpringMVC目录汇总贴、PDF下载、源码下载
- STL的算法补充笔记-1
- 2015.5.11 string与byte[]相互转换
- 一位大牛架构师的经验总结
- 【python、pyqt5】,打包出现的若干问题
- 大数据入门的知识体系,大数据学习路线
- python数据分析师网易云课堂_网易云课堂 数据分析(一)
- golang学习和校招经历
- gcc编译-m32、-mx32有什么区别
- AI-人工智能 easyAi开发技术
- 利用halcon识别汽车检具孔面积和孔间距
- Apache文件解析漏洞
- 知之者不如好之者 好之者不如乐之者
- 利用FPGA仿真软件modelsim仿真波形显示图片
- 【MATLAB编程实战】【例题实战】绘制曲面、曲线,求解偏导,计算极值点,二重积分,曲线积分,收敛性,麦克劳林展开式
- 2-6-RHEL6.5搭建vsftpd服务器案例分析与总结(Red Hat Enterprise Linux Server6.3)@树袋飘零...