Anagrams

devtools/2024/9/20 1:17:46/ 标签: 字符串
描述

Most crossword puzzle(猜字谜) fans are used to anagrams(字谜)--groups of words with the same letters in different orders--for example OPTS, SPOT, STOP, POTS and POST. Some words however do not have this attribute, no matter how you rearrange their letters, you cannot form another word. Such words are called ananagrams(变位词, an example is QUIZ.

Obviously such definitions depend on the domain(领域) within which we are working; you might think that ATHENE is an ananagram, whereas any chemist would quickly produce ETHANE. One possible domain would be the entire English language, but this could lead to some problems. One could restrict the domain to, say, Music, in which case SCALE becomes arelative ananagram (LACES is not in the same domain) but NOTE is not since it can produce TONE.

Write a program that will read in the dictionary of a restricted domain and determine the relative ananagrams. Note that single letter words are, ipso facto, relative ananagrams since they cannot be ``rearranged'' at all. The dictionary will contain no more than 1000 words.

输入

Input will consist of a series of lines. No line will be more than 80 characters long, but may contain any number of words. Words consist of up to 20 upper and/or lower case letters, and will not be broken across lines(跨行中断). Spaces may appear freely around words, and at least one space separates multiple words on the same line. Note that words that contain the same letters but of differing case are considered to be anagrams of each other, thus tIeD and EdiT are anagrams. The file will be terminated by a line consisting of a single #.

输出

Output will consist of a series of lines. Each line will consist of a single word that is a relative ananagram in the input dictionary. Words must be output in lexicographic(字典式的) (case-sensitive) order. There will always be at least one relative ananagram.

样例输入
ladder came tape soon leader acme RIDE lone Dreis peatScAlE orb  eye  Rides dealer  NotE derail LaCeS  drIed
noel dire Disk mace Rob dries
#
样例输出
Disk
NotE
derail
drIed
eye
ladder
soon

思路

用到两种数据结构map和set,map存入单词(在转换为小写且按照字母升序顺序后),set存入输入的单词

code

#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<map>
#include<string>
#include<algorithm>
#include<set> 
#include<sstream>
using namespace std;int main()
{string input;map<string, int> mp;set<string> st;while (getline(cin, input) && input != "#") {istringstream is(input);string word;while (is >> word) {string word1 = word;transform(word1.begin(), word1.end(), word1.begin(), ::tolower);//将单词转换为小写sort(word1.begin(), word1.end());mp[word1]++;st.insert(word);}}for (set<string>::iterator iter = st.begin(); iter != st.end(); iter++) {string temp = *iter;transform(temp.begin(), temp.end(), temp.begin(), ::tolower);sort(temp.begin(), temp.end());if (mp[temp] == 1) {cout << *iter << endl;}}return 0;
}

http://www.ppmy.cn/devtools/17068.html

相关文章

【第六章】集合类:List、Iterator迭代器

目录 1.集合类 1.1 什么是集合类 1.2 集合类的分类 2.Collection接口 3.List集合 3.1 ArrayList集合 3.2 LinkedList集合 3.3 ArrayList和LinkedList对比 3.4 创建List对象 4 Iterator接口 5 foreach循环 6 代码练习 1.集合类 1.1 什么是集合类 集合类就像一个容器&a…

前端实现页面文本复制/代码复制/mardown复制的几种方式

1.复制文本【安全环境下-localhost或者https】 <button class"btn" onclick"copy1()">复制文本</button>function copy1() {navigator.clipboard.writeText(普通)}2.复制文本【所有环境都可用】 function copy(val){const textarea document…

Jenkins CI/CD 持续集成专题一 Jenkins的安装和配置

一 jenkins 官方教程 安装Jenkins 二 安装 2.1 安装方式一 通过安装包的package方式安装 第一步下载链接&#xff1a; Download the latest package 第二步操作方式&#xff1a;打开包并按照说明操作即可安装 2.2 安装方式二 brew安装 第一 安装最新版本jenkins brew in…

线性代数:抽象向量空间

一、说明 有些函数系列极具线性代数的向量特征。这里谈及多项式构成函数的线性代数意义。问题是这个主题能展开多少内涵&#xff1f;请看本文的论述。 二、线性空间和向量 让我先问你一个简单的问题。什么是向量&#xff1f;为了方便起见&#xff0c;二维箭头从根本上说是平…

OpenHarmony鸿蒙南向开发案例:【智能窗户通风设备】

样例简介 本文档介绍了安全厨房案例中的相关智能窗户通风设备&#xff0c;本安全厨房案例利用轻量级软总线能力&#xff0c;将两块欧智通V200Z-R/BES2600开发板模拟的智能窗户通风设备和燃气告警设备组合成。当燃气数值告警时&#xff0c;无需其它操作&#xff0c;直接通知软总…

AI绘画的算法原理:从生成模型到Diffusion

近年来&#xff0c;AI绘画技术引起了广泛关注&#xff0c;让我们深入探讨其背后的技术原理和发展历程。本文将以通俗易懂的方式&#xff0c;介绍AI绘画的核心算法&#xff0c;从生成模型到Diffusion。 1. 计算机如何生成图画&#xff1f; AI绘画的核心在于生成模型&#xff08…

vscode 正则匹配 用途总结

找出所有汉字 (.[\u4E00-\u9FA5])|([\u4E00-\u9FA5].) 找出所有注释 \/\*[\s\S]*\*\/|\/\/.* 匹配所有空行 ^\s*(?\r?$)\n

使用PaddlePaddle和Ernie模型来计算文本数据的向量表示

import paddle 2from paddlenlp.transformers import ErnieTokenizer, ErnieModel 3import numpy as np 4import json 5 6# 设置PaddlePaddle的全局随机种子 7paddle.seed(1234) 8 9# 初始化分词器 10tokenizer ErnieTokenizer.from_pretrained(ernie-3.0-tiny-medium-v2-zh) …

CSS 标准流 浮动 Flex布局

目录 1. 标准流2. 浮动2.1 清除浮动 3. Flex 布局3.1 Flex 组成3.2 Flex 布局 - 主轴与侧轴对齐方式3.2.1 主轴对齐方式3.2.2 侧轴对齐方式 3.3 Flex 布局 - 修改主轴方向3.4 Flex 布局 - 弹性伸缩比3.5 Flex 布局 - 弹性盒子换行3.6 Flex 布局 - 行对齐方式 1. 标准流 标准流…

Current browser version is 101.0.4951.54 with binary解决

目录 问题&#xff1a; 原因&#xff1a; 解决&#xff1a; 1. 卸载浏览器 2.安装新浏览器&#xff0c;取消自动更新 3.安装chromedriver.exe 问题&#xff1a; 今天在使用python selenium进行爬虫时&#xff0c;突然报错&#xff0c;前2天还正常使用 Current browser ve…

JVM 面试题

1. 什么情况下会发生栈内存溢出&#xff1f; 当线程调用堆栈深度超过虚拟机所允许的最大深度时&#xff0c;会抛出StackOverflowError。如果一个线程请求的栈深度超过了虚拟机的允许范围&#xff0c;会抛出OutOfMemoryError。 2. 说一下 JVM 的主要组成部分及其作用&#xff…

C#关键字汇总

C#是一种强大且灵活的编程语言&#xff0c;拥有许多关键字&#xff0c;用于声明类型、变量、方法、类等。以下是C#中的一些主要关键字和它们的简要描述&#xff1a; 1.访问修饰符&#xff1a; public&#xff1a;访问不受限制。 private&#xff1a;访问仅限于当前类。 prot…

iframe实现pdf预览,并使用pdf.js修改内嵌标题,解决乱码问题

项目中遇到文件预览功能,并且需要可以打印文件.下插件对于内网来说有点麻烦,正好iframe预览比较简单,且自带下载打印等功能按钮. 问题在于左上方的文件名乱码,网上找了一圈没有看到解决的,要么就是要收费要会员(ztmgs),要么直接说这东西改不了. 使用: 1.引入 PDF.js 库&…

modelsim波形高度异常,值为X

一、问题 波形高度异常&#xff0c;忽高忽低&#xff0c;正常波形高电平和低电平是统一高度的 timescale 1ns/1nsmodule key_test_tb();//parameter define parameter CLK_PERIOD 20; parameter CNT_MAX 25d25; //仅用于仿真,对应 500nsreg sys_clk; //周期 20ns reg d; wir…

css 将div固定在页面顶部不随页面滑动

为了将一个 div 设置为固定在页面顶部&#xff0c;并且高度为 5rem&#xff0c;宽度为 100vw&#xff0c;不随页面滚动&#xff0c;可以使用几种不同的 CSS 技术来实现。下面我将列举几种常见的方法&#xff1a; 1. 使用 position: fixed 最直接的方法是使用 position: fixed…

c# 字典与内存碎片化

在 C# 中&#xff0c;字典&#xff08;Dictionary&#xff09;的频繁添加和删除操作不会导致传统意义上的内存碎片化&#xff0c;因为 .NET 运行时使用的是垃圾回收&#xff08;GC&#xff09;机制来管理内存。这意味着内存分配和释放是由 GC 控制的&#xff0c;而 GC 会定期整…

基于vue+node+mysql的视频校对系统

一、登录注册&#xff1a;包括登录&#xff0c;注册&#xff0c;忘记密码&#xff0c;验证码等常用点。 二、用户管理&#xff1a;包括用户的增删改查 三、权限管理&#xff08;请增加这个权限&#xff1a;任务分配——只有管理者才能发布和删除任务&#xff1b;管理员设置。 四…

OSPF的LSA详解

一、什么是LSA&#xff1f;LSA作用&#xff1f; 在OSPF协议中&#xff0c;LSA全称链路状态通告&#xff0c;主要由LSA头部信息&#xff08;LSA摘要&#xff09;和链路状态组成。部分LSA只有LSA头部信息&#xff0c;无链路状态信息。使用LSA来传递路由信息和拓扑信息&#xff0c…

Docker镜像的创建 和 Dockerfile

一. Docker 镜像的创建 创建镜像有三种方法&#xff0c;分别为基于已有镜像创建、基于本地模板创建以及基于 Dockerfile 创建。 1 基于现有镜像创建 &#xff08;1&#xff09;首先启动一个镜像&#xff0c;在容器里做修改docker run -it --name web3 centos:7 /bin/bash …

AJAX——封装_简易axios

1.简易axios_获取身份列表 需求&#xff1a;基于Promise XHR 封装 myAxios函数&#xff0c;获取省份列表展示 步骤&#xff1a; 1.定义 myAxios函数&#xff0c;接收配置对象&#xff0c;返回Promise对象 2.发起XHR请求&#xff0c;默认请求方法为GET 3.调用成功/失败的处…