Time limit(ms): 1000        Memory limit(kb): 65535
 
Description

输入N和一个要查找的字符串,以下有N个字符串,我们需要找出其中的所有待查找字符串的变位词(例如eat,eta,aet就是变位词)按字典序列输出,并且输出总数目

Input

第一行:N(代表共有N个字符串属于被查找字符串) (N<=50) 第二行:待查找的字符串(不大于10个字符) 以下N行:被查找字符串(不大于10个字符)

 
Output

按字典序列输出在被查找字符串中待查找字符串的所有变位词 每行输出一个 输出完成后输出总数目

Sample Input
7
asdfg
asdgf
asdfg
dsafg
xcvcv
gfdsa
tyuv
asd
Sample Output
asdfg
asdgf
dsafg
gfdsa
4
 
 
 
嗯~~没什么好说的水题,运用vector直接水过 ,Orz~~
代码如下:
 #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
bool judge(string a,string b){
sort(a.begin(),a.end());
sort(b.begin(),b.end());
return a==b?true:false;
}
int main(){
string a,b;
vector<string> mpt;
vector<string>::iterator it;
int n,i;
cin>>n>>a;
for(i=;i<n;i++){
cin>>b;
if(judge(a,b)) mpt.push_back(b);
}
sort(mpt.begin(),mpt.end());
for(it=mpt.begin();it!=mpt.end();it++)
cout<<*it<<endl;
cout<<mpt.size()<<endl;
return ;
}

[Swust 549]--变位词(vector水过)的更多相关文章

  1. 变位词(0029)-swustoj

    变位词(0029)水题 变位词如果两个单词的组成字母完全相同,只是字母的排列顺序不一样,则它们就是变位词,两个单词相同也被认为是变位词.如tea 与eat , nic 与cin, ddc与dcd, a ...

  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. “《编程珠玑》(第2版)第2章”:C题(查找变位词,排序)

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

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

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

  5. 【图灵杯 J】简单的变位词

    Description 变位词是指改变某个词的字母顺序后构成的新词.蔡老板最近沉迷研究变位词并给你扔了一道题: 给你一些单词,让你把里面的变位词分组找出来.互为变位词的归为一组,最后输出含有变位词最多 ...

  6. [LeetCode] 49. Group Anagrams 分组变位词

    Given an array of strings, group anagrams together. For example, given: ["eat", "tea& ...

  7. 剑指Offer:互为变位词

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

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

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

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

随机推荐

  1. Java 日期字符串与日期类型转换

    1.SimpleDateFormat.format 把日期类型转化到指定格式字符串 public static String convToString(Calendar cld,String temp ...

  2. isinstance 和 issubclass

    一.isinstance Python 中的isinstance函数 isinstance是Python中的一个内建函数 语法: isinstance(object, classinfo) 如果参数o ...

  3. java 显示视频时间--玩的

    1.显示视频时间 package view.time; import it.sauronsoftware.jave.Encoder; import it.sauronsoftware.jave.Mul ...

  4. Sublime 编辑器主题

    Sublime主题分为两种 一种是编辑框中的代码的颜色  另一种是编辑器本身的颜色(不只是颜色哟  Sublime编辑器左边侧边栏的字很小对不对 !有了主题就可以改) 这个主题叫做Soda  http ...

  5. C 根据行来读取文件 字符串的截取

    // TestCFile.cpp : Defines the entry point for the console application. // #include "stdafx.h&q ...

  6. Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

    2016-07-18 16:08:20 [main:53] - [WARN] Exception encountered during context initialization - cancell ...

  7. java面试复习 I

    1 多线程 在程序开发中只要是多线程肯定永远以实现Runnable接口为主,因为实现Runnable接口相比继承Thread类有如下好处: 避免点继承的局限,一个类可以继承多个接口. 适合于资源的共享 ...

  8. docpad建站记录

    记一下用docpad建站的过程作为备忘.不定时更新 why docpad wordpress对我来说太过于臃肿,我就想要个代码干净的小站来写东西.想要个markdown为基础的静态站. 比较流行的St ...

  9. hdu5188 加限制的01背包问题

    http://acm.hdu.edu.cn/showproblem.php? pid=5188 Problem Description As one of the most powerful brus ...

  10. hdu 3966 Aragorn&#39;s Story(树链剖分+树状数组)

    pid=3966" target="_blank" style="">题目链接:hdu 3966 Aragorn's Story 题目大意:给定 ...