CF975A Aramic script(找词根)set的使用

本文介绍了一种算法,用于解决Aramic语言中不同对象的计数问题。通过处理一系列单词,去除重复字母并排序,利用C++ set集合的特性来统计不同根单词的数量。

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

题目描述(洛谷上的cf题CF975A Aramic script)
In Aramic language words can only represent objects.

Words in Aramic have special properties:

A word is a root if it does not contain the same letter more than once.
A root and all its permutations represent the same object.
The root x x of a word y y is the word that contains all letters that appear in y y in a way that each letter appears once. For example, the root of “aaaa”, “aa”, “aaa” is “a”, the root of “aabb”, “bab”, “baabb”, “ab” is “ab”.
Any word in Aramic represents the same object as its root.
You have an ancient script in Aramic. What is the number of different objects mentioned in the script?

输入输出格式
输入格式:
The first line contains one integer n n ( 1 \leq n \leq 10^3 1≤n≤10
3
) — the number of words in the script.

The second line contains n n words s_1, s_2, \ldots, s_n s
1
​ ,s
2
​ ,…,s
n
​ — the script itself. The length of each string does not exceed 10^3 10
3
.

It is guaranteed that all characters of the strings are small latin letters.

输出格式:
Output one integer — the number of different objects mentioned in the given ancient Aramic script.

#include<iostream>
#include<set>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
char a[1000];
int main()
{   
    set<string>ss;           //注意是string不是char,一个是串一个是个
    int n,i,sum=0,len;
    cin>>n;
    for(i=0;i<n;i++)
     {
     	scanf("%s",a);
     	sort(a,a+strlen(a));
     	len=unique(a,a+strlen(a))-a;
     	a[len]='\0';     //unique只是把重复的字母丢到后面去了所以加一个结束符号使得后面重复的被去掉
     	ss.insert(a); //一个一个插入ss中,利用set的不重复性可以轻易的得到根的数目
	 }   
	 cout<<ss.size()<<endl;
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值