文章

55

粉丝

57

获赞

11

访问

11.4k

头像
变位词 题解:C++ sort排序 去重 用map匹配出现次数
P1032
发布于2024年3月22日 01:10
阅读数 170

#include<stdio.h>
#include<iostream>
#include<vector>
#include<string.h>
#include<string>
#include<algorithm>
#include<map>
using namespace std;

int main(){
	int n;
	cin>>n;
	while(n--){
        //初始化两个map
		map<char,int> myMap1;
		for(int i = 0; i<27; i++){
			char a = 'a'+i;
			myMap1[a] = 0;
		}
		map<char,int> myMap2;
		for(int i = 0; i<27; i++){
			char a = 'a'+i;
			myMap2[a] = 0;
		}
		char str1[1000];
		char str2[1000];
		cin>>str1>>str2;
		int len1 = strlen(str1);
		int len2 = strlen(str2);;
		bool flag = true;
		for(int i = 0; i<len1; i++){
			myMap1[str1[i]]++;
		}
		for(int i = 0; i<len2; i++){
			myMap2[str2[i]]++;
		}
		sort(str1,str1+len1);
		sort(str2,str2+len2);
		string s1 = "";
		string s2 = "";
		for(int i = 0; i< len1-1; i++){
			if(str1[i] != str1[i+1]){
				s1+=str1[i];
			}
		}
		s1+=str1[len1-1];
		for(int i = 0; i<len2-1...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发