CodeForces - 975A:Aramic script(字符串)

39 篇文章 1 订阅

链接https://vjudge.net/problem/CodeForces-975A

题目
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 of a word y is the word that contains all letters that
    appear in 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?

题意
在神奇的Aramic语言中,每个单词都有自己的词根,你的任务就是算出给出的单词一共有几个词根
例如“aabb”,去掉重复的字母之后就是“ab”,那么“ab”就是它的词根。
对于“aabb”和“bbaa”来说,它们的词根都是“ab”,只不过是顺序问题。

思路
这题思路很清晰:把输入的单词存起来,然后把每个单词的词根全部求出来放到一起,看一下有几个不同的词根就ok。
那么就涉及到除同操作,这个就可以放心交给set了。
看代码,伊丽莎白!

在这里插入图片描述
代码

#include <iostream>
#include<cstdio>
#include<cstring>
#include<set>
using namespace std;
typedef long long ll;
const int maxn=1500;

int main()
{
    int n;
    string ss[maxn];
    set<string>s;
    set<char>x;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>ss[i];
    for(int i=0; i<n; i++)
    {
        x.clear();
        string s1="";
        for(int j=0; j<ss[i].size(); j++)   //求每个单词的词根
            x.insert(ss[i][j]);
        set<char>::iterator it;
        for(it=x.begin();it!=x.end();it++)
            s1+=(*it);
        s.insert(s1);
    }
    cout<<s.size()<<endl;
}

《可能是最近作孽有点多导致鼻子长了个痘真的是折磨》

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值