变位词(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的更多相关文章

  1. 剑指Offer:互为变位词

    // 判断两个单词是否互为变位词: 如果两个单词中的字母相同,并且每个字母出现的次数也相同, 那么这两个单词互为变位词 #include <stdio.h> #include <st ...

  2. 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 = & ...

  3. [Swust 549]--变位词(vector水过)

    Time limit(ms): 1000 Memory limit(kb): 65535   Description 输入N和一个要查找的字符串,以下有N个字符串,我们需要找出其中的所有待查找字符串的 ...

  4. “《编程珠玑》(第2版)第2章”:C题(查找变位词,排序)

    C题是这样子的: 给定一个英语字典,找出其中的所有变位词集合.例如,“pots”.“stop”和“tops”互为变位词,因为每一个单词都可以通过改变其他单词中字母的顺序来得到. 下段分析摘自该书(P1 ...

  5. 南大算法设计与分析课程OJ答案代码(4)--变位词、三数之和

    问题 A: 变位词 时间限制: 2 Sec  内存限制: 10 MB提交: 322  解决: 59提交 状态 算法问答 题目描述 请大家在做oj题之前,仔细阅读关于抄袭的说明http://www.bi ...

  6. [leetcode]49. Group Anagrams变位词归类

    Given an array of strings, group anagrams together. Example: Input: ["eat", "tea" ...

  7. [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: ...

  8. lintcode-158-两个字符串是变位词

    158-两个字符串是变位词 写出一个函数 anagram(s, t) 判断两个字符串是否可以通过改变字母的顺序变成一样的字符串. 说明 What is Anagram? Two strings are ...

  9. 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 ...

随机推荐

  1. MySQL基础函数

    MySQL数据库提供了很多函数包括: 数学函数: 字符串函数: 日期和时间函数: 条件判断函数: 系统信息函数: 加密函数: 格式化函数: 一.数学函数 数学函数主要用于处理数字,包括整型.浮点数等. ...

  2. python第三课

    本节内容 1.列表 2.购物车设计思路 3.字典 1.列表 不可变类型:整型.字符串.元组tuple 可变类型:列表list.字典dict 2.购物车 3.字典

  3. web.xml中<init-param>报错

    报错信息如下图: 控制台报错:严重: Servlet /*** threw load() exceptionjava.lang.ClassNotFoundException: MyApplicatio ...

  4. angular-utils-ui-breadcrumbs使用心得

    angular-utils-ui-breadcrumbs是一个用来自动生成面包屑导航栏的一个插件,需要依赖angular.UIRouter和bootstrap3.css.生成的界面截图如下,点击相应的 ...

  5. C语言程序内存布局

    C语言程序内存布局 如有转载,请注明出处:http://blog.csdn.net/embedded_sky/article/details/44457453 作者:super_bert@csdn 一 ...

  6. A Simple Game

    A Simple Game Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/65535 K (Java/Others) Total ...

  7. C++中模板template <typename T>

    最近在看C++的源码,遇到了不少问题,一点一点进行补充. 首先就是遇到template <typename Dtype>. 网上解释的非常多,觉得比较啰嗦,其实就是一个类型模板. 比如我们 ...

  8. Node.js Web 模块

    什么是 Web 服务器? Web服务器一般指网站服务器,是指驻留于因特网上某种类型计算机的程序,Web服务器的基本功能就是提供Web信息浏览服务.它只需支持HTTP协议.HTML文档格式及URL,与客 ...

  9. Node.js Stream(流)

    Stream 是一个抽象接口,Node 中有很多对象实现了这个接口.例如,对http 服务器发起请求的request 对象就是一个 Stream,还有stdout(标准输出). Node.js,Str ...

  10. js 函数声明和函数表达式

    在ECMAScript中,创建函数的最常用的两个方法是函数表达式和函数声明,因为ECMA规范只明确了一点:函数声明必须带有标示符(Identifier)(就是大家常说的函数名称),而函数表达式则可以省 ...