请教站外题
  • 板块题目总版
  • 楼主zhangzirui66
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/8/5 19:13
  • 上次更新2024/8/5 20:26:44
查看原帖
请教站外题
1137373
zhangzirui66楼主2024/8/5 19:13

rt,只得了70分,请教各位神犇,谢谢。

My Code:

#include<bits/stdc++.h>
using namespace std;
vector<string> s;
string str;
map<string, bool> mp;
string change(string& word){
    if(word.size() <= 2){
        return word;
    }
    string mid = word.substr(1, word.size() - 2);
    sort(mid.begin(), mid.end());
    return word.front() + mid + word.back();
}
bool check(){
    string y = change(str);
    if(mp[y] == 1) return 1;
    return 0;
}
int main(){
	int n, m;
	cin >> n >> m;
    for(int i = 1; i <= n; i ++){
    	string str;
    	cin >> str;
    	s.push_back(str);
	}
	for(auto& word : s){
		string str = change(word);
		mp[str] = 1;
	}
	for(int i = 1; i <= m; i ++){
		cin >> str;
		if(check()) cout << "Yes\n";
	    else cout << "No\n";
	}
    return 0;
}

思路:将会的单词内部排序,与不会的单词作比较。

结局:


求助,谢谢。

2024/8/5 19:13
加载中...