变位词(0029)-swustoj
变位词(0029)
水题 变位词
如果两个单词的组成字母完全相同,只是字母的排列顺序不一样,则它们就是变位词,两个单词相同也被认为是变位词。如tea 与eat , nic 与cin, ddc与dcd, abc与abc 等。你的任务就是判断它们是否是变位词。
Description
第一行一个N,表示下面有N行测试数据。每行测试数据包括两个单词,如tea eat ,它们之间用空格割开
Input
对于每个测试数据,如果它们是变位词,输出Yes,否则输出No.
Output
3
tea eat
ddc cdd
dee dde
Sample Input
Yes
Yes
No
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
int n,i;
while(cin>>n)//定义输入的个数
{
for(i=;i<n;i++)
{
char str1[],str2[];//定义字符串
cin>>str1>>str2;
int len1,len2;
len1=strlen(str1);
len2=strlen(str2);
sort(str1,str1+len1);//排序
sort(str2,str2+len2);
if(strcmp(str1,str2)==)//比较
{
printf("Yes\n");
}
else
{
printf("No\n");
}
}
}
return ;
}
变位词(0029)-swustoj的更多相关文章
- 剑指Offer:互为变位词
// 判断两个单词是否互为变位词: 如果两个单词中的字母相同,并且每个字母出现的次数也相同, 那么这两个单词互为变位词 #include <stdio.h> #include <st ...
- Leetcode 242. Valid Anagram(有效的变位词)
Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = & ...
- [Swust 549]--变位词(vector水过)
Time limit(ms): 1000 Memory limit(kb): 65535 Description 输入N和一个要查找的字符串,以下有N个字符串,我们需要找出其中的所有待查找字符串的 ...
- “《编程珠玑》(第2版)第2章”:C题(查找变位词,排序)
C题是这样子的: 给定一个英语字典,找出其中的所有变位词集合.例如,“pots”.“stop”和“tops”互为变位词,因为每一个单词都可以通过改变其他单词中字母的顺序来得到. 下段分析摘自该书(P1 ...
- 南大算法设计与分析课程OJ答案代码(4)--变位词、三数之和
问题 A: 变位词 时间限制: 2 Sec 内存限制: 10 MB提交: 322 解决: 59提交 状态 算法问答 题目描述 请大家在做oj题之前,仔细阅读关于抄袭的说明http://www.bi ...
- [leetcode]49. Group Anagrams变位词归类
Given an array of strings, group anagrams together. Example: Input: ["eat", "tea" ...
- [leetcode]242. Valid Anagram验证变位词
Given two strings s and t , write a function to determine if t is an anagram of s. Example 1: Input: ...
- lintcode-158-两个字符串是变位词
158-两个字符串是变位词 写出一个函数 anagram(s, t) 判断两个字符串是否可以通过改变字母的顺序变成一样的字符串. 说明 What is Anagram? Two strings are ...
- LeetCode 438. Find All Anagrams in a String (在字符串中找到所有的变位词)
Given a string s and a non-empty string p, find all the start indices of p's anagrams in s. Strings ...
随机推荐
- NodeJs通过镜像下载相关NPM模块
临时通过镜像使用一次:npm --registry https://registry.npm.taobao.org install 模块名[设置镜像源地址为淘宝] 持久使用的第一种方法: npm c ...
- LeetCode 501. Find Mode in Binary Search Tree (找到二叉搜索树的众数)
Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred ...
- 用Unity3d做游戏(一)
准备工作: vs2013,直接从官网下载或者这里 http://pan.baidu.com/s/1bFxC54 unity3d,从官网下载,版本4或者5 https://unity3d.com/c ...
- 最新版multer1.3.0上传文件
完整项目资源下载路径:http://download.csdn.net/detail/qq_28506819/9851744 使用方法: cd到跟目录,然后npm install. 运行项目,npm ...
- [C#]使用ILMerge将源DLL合并到目标EXE(.NET4.6.2)
本文为原创文章,如转载,请在网页明显位置标明原文名称.作者及网址,谢谢! 本文主要是使用微软的ILMerge工具将源DLL合并到目标EXE,因此,需要下载以下工具: https://www.micro ...
- python web框架篇:views视图函数
Django请求的生命周期是怎样的? 简单地说,通过URL对应关系匹配 ->找到对应的函数(或者类)->返回字符串(或者读取Html之后返回渲染的字符串) 解剖起来如下: 1. 当用户在浏 ...
- Windows Nodejs 安装教程
Windows Nodejs 安装教程 1: 访问官方地址 https://nodejs.org/en/download/ 2: 解压压缩包文件到指定目录 我直接把压缩包解压到C盘根目录下,并将文件夹 ...
- Python基础学习参考(二):基本语法
一.基本语法 既然是学习一门语言,它肯定有区别与其它语言的语法规则,现在就来解释一下python的语法规则是什么? 注释:通过"#"可以对python进行注释,注意是单行注释,如果 ...
- Log4j – Configuring Log4j 2 - Log4j 2的配置
Configuration Inserting log requests into the application code requires a fair amount of planning an ...
- AngularJS学习篇(八)
AngularJS 服务(Service) 在 AngularJS 中,服务是一个函数或对象,可在你的 AngularJS 应用中使用. AngularJS 内建了30 多个服务. 为什么使用服务? ...