首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >【51Nod】1095 - Anigram单词(STL - map)

【51Nod】1095 - Anigram单词(STL - map)

作者头像
FishWang
发布2025-08-27 12:13:01
发布2025-08-27 12:13:01
1250
举报

题目链接:点击打开题目


这里写图片描述
这里写图片描述

题解:直接用map记录,然后排序再记录,相减就求出来了。


代码如下:

代码语言:javascript
复制
#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define CLR(a,b) memset(a,b,sizeof(a))
#define PI acos(-1.0)
#define LL long long
int main()
{
    int n;
    map<string,int> a;      //字符串出现次数 
    map<string,int> b;      //排序后字符串出现次数 
    string str;
    scanf ("%d",&n);
    while (n--)
    {
        cin >> str;
        a[str]++;
        sort(str.begin(),str.end());
        b[str]++;
    }
    scanf ("%d",&n);
    while (n--)
    {
        cin >> str;
        int x = a[str];
        sort(str.begin(),str.end());
        int y = b[str];
        printf ("%d\n",y-x);
    }
    return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2025-08-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档