欢乐赛#67 T4 题解
2026-02-15 22:12:52
发布于:云南
1阅读
0回复
0点赞
题目大意
@skirmish 有一个字符矩阵,且每个大写字母最多出现 次。按照字母表的顺序输出每个大写字母及其行号、列号。如果没有大写字母输出not found。
解题思路
模拟。
遍历字符矩阵,若当前字母为大写字母,则把字母及其行号、列号存在std::map<char,std::pair<int,int>>中,最后输出。
也可以存在结构体数组中,但最后还要排序,不如std::map自带排序。
Code
时间复杂度:。
#include <bits/stdc++.h>
using namespace std;
int n,m;
char a[1005][1005];
map<char,pair<int,int>> mp;//按照 first 排序,即字母 ASCII 从小到大
int main(){
cin>>n>>m;
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++){
cin>>a[i][j];
if (a[i][j]>='A'&&a[i][j]<='Z'){
mp[a[i][j]]={i,j};
}
}
}
for (auto it=mp.begin();it!=mp.end();it++){
cout<<it->first<<' '<<it->second.first<<' '<<it->second.second<<'\n';
}
if (mp.empty()){//没有大写字母
cout<<"not found";
}
return 0;
}
这里空空如也







有帮助,赞一个