03 | #循环单词#

/* 采用排序+哈希可以快速解决此问题 */
#include <bits/stdc++.h>
using namespace std;

int n = 0;
string calc(string s){
    vector<string> v;
    int m = s.length();
    for (int i = 0; i < m; i++) {
        string tmp = s;
        for (int j = 0; j < m; j++) {
            tmp[j] = s[(j + i) % m];
        }
        v.push_back(tmp);
    }
    sort(v.begin(),v.end());
    return v[0];
}

int main() {
    set<string> s;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string x;
        cin >> x;
        s.insert(calc(x));
    }
    cout << s.size() << endl;
}
每日算法 文章被收录于专栏

每日算法、玩转技术、聪明理财、幸福生活!

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-09 12:11
点赞 评论 收藏
分享
星辰再现:裁员给校招生腾地方
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-11 11:22
怎么这么多逆天求职者,救救我救救我救救我😭
flmz_Kk:哈哈哈哈哈哈,这么多求职者,肯定有那一两个逆天的
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务