#include<iostream>
#include<fstream>
#include<algorithm>
#include<vector>
using namespace std;
static bool com(pair<string, string> a, pair<string, string> b) {
	if (a.first != b.first) return a.first < b.first;
	else return a.second < b.second;
}
static bool com1(string a, string b) {
	return a < b;
}
int main() {
	ifstream in("text1.txt");
	string a;
	vector<string> sig;
	while (in >> a) sig.push_back(a);
	ofstream out("text2.txt");
	vector<pair<string, string>> sor;
	for (int i = 0; i < sig.size(); i++) {
		string temp = sig[i];
		sort(temp.begin(), temp.end());
		pair<string, string> pa(temp, sig[i]);
		sor.emplace_back(pa);
		 
		
	}
	sort(sor.begin(), sor.end(), com);
	for (int i = 0; i < sor.size(); i++)
		out << sor[i].first << " " << sor[i].second << endl;
	ofstream out1("text3.txt");
	string temp = sor[0].first;
	int linenum = 0;
	for (int i = 0; i < sor.size(); i++) {
		if (sor[i].first != temp && linenum > 0) {
			out1 << endl;
			temp = sor[i].first;
		}
		
		out1 << sor[i].second << " ";
		//temp = sor[i].second;
		linenum++;
	}
	return 0;
	
}
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐