755 - 487--3279

本文详细阐述了如何解析输入的复杂字符串,通过特定规则进行转换,并去除重复元素,最终输出去重后的结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <iostream>
#include <map>
#include <vector>
#include <list>
#include <string>

using namespace std;

int main ( int argc, char * argv[ ] ) {
	int n, N;
	cin >> N;
	for ( n = 0; n < N; n++ ) {
		if ( n ) cout << endl;

		int m, M;
		cin >> M;

		map<string, int> map_r;

		for ( m = 0; m < M; m++ ) {
			string ts;
			while ( ts == "" || ts[0] == '\n' ) getline ( cin, ts );

			int pos;
			while ( ( pos = ts.find("-", 0) ) != string::npos ) ts.erase ( pos, 1 );

#define R(X, Y) while ( ( pos = ts.find( #X, 0 ) ) != string::npos ) { ts.erase ( pos, 1 ); ts.insert ( pos, #Y ); }

			R(A, 2)
			R(B, 2)
			R(C, 2)
			R(D, 3)
			R(E, 3)
			R(F, 3)
			R(G, 4)
			R(H, 4)
			R(I, 4)
			R(J, 5)
			R(K, 5)
			R(L, 5)
			R(M, 6)
			R(N, 6)
			R(O, 6)
			R(P, 7)
			R(R, 7)
			R(S, 7)
			R(T, 8)
			R(U, 8)
			R(V, 8)
			R(W, 9)
			R(X, 9)
			R(Y, 9)

			ts.insert ( 3, "-" );

			map_r[ ts ] ++;
		}

		map<string, int> map_2;
		for ( auto i : map_r ) {
			if ( i.second > 1 ) map_2[ i.first ] = i.second;
		}

		bool tick = true;
		for ( auto i : map_2 ) {
			tick = false;
			cout << i.first << " " << i.second << endl;
		}
		if ( tick ) cout << "No duplicates." << endl;
	}

	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值