hdu - 1113 Word Amalgamation (stl)
http://acm.hdu.edu.cn/showproblem.php?pid=1113
给定一个字典,然后每次输入一个字符串问字典中是否有单词与给定的字符串的所有字母一样(顺序可以打乱),按字典序输出字典中的原字符串。
我开始是直接用了 sort, 用一个结构体记录了所有字符串,和相应下标,输出的时候在用了冒泡排序。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue>
#pragma comment(linker, "/STACK:102400000,102400000")
#define CL(arr, val) memset(arr, val, sizeof(arr)) #define ll long long
#define inf 0x7f7f7f7f
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0) #define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("a.txt", "r", stdin)
#define Write() freopen("b.txt", "w", stdout);
#define maxn 1000000000
#define N 2510
#define mod 1000000000
using namespace std; struct node
{
string s[];
int x;
};
node s1,s2,s3;
int main()
{
//freopen("a.txt","r",stdin);
int n=;
string str;
while(cin>>str)
{
if(str=="XXXXXX")break;
s1.s[n++]=str;
}
//cout<<n<<endl;
for(int i=;i<n;i++)
{
s2.s[i]=s1.s[i];
sort(s1.s[i].begin(),s1.s[i].end());
}
while(cin>>str)
{
if(str=="XXXXXX") break;
sort(str.begin(),str.end());
bool flag=;
int k=;
for(int j=;j<n;j++)
if(str==s1.s[j])
{
flag=;
s3.s[k++]=s2.s[j];
}
for(int i=;i<k;i++)
for(int j=i+;j<k;j++)
{
if(s3.s[i]>s3.s[j])
{
str=s3.s[i];
s3.s[i]=s3.s[j];
s3.s[j]=str;
}
}
for(int i=;i<k;i++)
cout<<s3.s[i]<<endl;
if(!flag) cout<<"NOT A VALID WORD"<<endl;
cout<<"******"<<endl;
}
return ;
}
也可以直接sort排序,定义一个结构体,保存原字符串和排序后的字符串,先对所有字符串按照字典序排,这样先输出的就是字典序小的。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue>
#pragma comment(linker, "/STACK:102400000,102400000")
#define CL(arr, val) memset(arr, val, sizeof(arr)) #define ll long long
#define inf 0x7f7f7f7f
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0) #define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("a.txt", "r", stdin)
#define Write() freopen("b.txt", "w", stdout);
#define maxn 1000000000
#define N 2510
#define mod 1000000000
using namespace std; struct node
{
char s1[],s2[];
int id;
bool operator < (const node a) const
{
return strcmp(s1,a.s1)<;
}
}p[]; int main()
{
// freopen("a.txt","r",stdin);
char str[];
int n=;
while(~scanf("%s",p[n].s1))
{
if(strcmp(p[n].s1,"XXXXXX")==) break;
strcpy(p[n].s2,p[n].s1);
n++;
}
sort(p,p+n); //先对 所有字符串按照字典序排序
for(int i=;i<n;i++)
{
int l=strlen(p[i].s1);
sort(p[i].s1,p[i].s1+l); //再对 每个字符串排序
}
while(~scanf("%s",str))
{
if(strcmp(str,"XXXXXX")==) break;
int l=strlen(str);
sort(str,str+l);
bool flag=;
for(int j=;j<n;j++)
if(strcmp(p[j].s1,str)==)
{
flag=;
printf("%s\n",p[j].s2);
}
if(!flag) printf("NOT A VALID WORD\n");
printf("******\n");
}
return ;
}
hdu - 1113 Word Amalgamation (stl)的更多相关文章
- hdu 1113 Word Amalgamation
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 字符串简单题: stl水过 如下: #include<algorithm> #inc ...
- hdu 1113 Word Amalgamation 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 题意:输入一个字典,然后再输入若干单词(每行中,1 <= 单词数 <= 100,并且 ...
- HDU 1113 Word Amalgamation (map 容器 + string容器)
http://acm.hdu.edu.cn/showproblem.php?pid=1113 Problem Description In millions of newspapers across ...
- HDOJ/HDU 1113 Word Amalgamation(字典顺序~Map)
Problem Description In millions of newspapers across the United States there is a word game called J ...
- HDOJ.1113 Word Amalgamation(map)
Word Amalgamation 点我挑战题目 点我一起学习STL-MAP 题意分析 给出字典.之后给出一系列======乱序======单词,要求你查字典,如过这个乱序单词对用有多个有序单词可以输 ...
- hdu1113 Word Amalgamation(详解--map和string的运用)
版权声明:本文为博主原创文章.未经博主同意不得转载. vasttian https://blog.csdn.net/u012860063/article/details/35338617 转载请注明出 ...
- Word Amalgamation(枚举 + 排序)
Word Amalgamation Time Limit: 1 Sec Memory Limit: 64 MB Submit: 373 Solved: 247 Description In mil ...
- hdu-----(1113)Word Amalgamation(字符串排序)
Word Amalgamation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- Word Amalgamation(hdoj1113)
Word Amalgamation Problem Description In millions of newspapers across the United States there is a ...
随机推荐
- laravel 学习
解决办法:没有开启PHP.ini的fileinfo扩展
- 怪物猎人OL简单测评与碎碎念
请移步我的个人网站查看: www.wuduojia.cn
- 微信小程序组件解读和分析:十、input输入框
input输入框组件说明: 本文介绍input 输入框的各种参数及特性. input输入框示例代码运行效果如下: 下面是WXML代码: [XML] 纯文本查看 复制代码 ? 01 02 03 04 0 ...
- Git ---创建和切换分支
······································································"天下武功,唯快不破" git分支: g ...
- Android学习笔记(八) CheckBox和RadioGroup
一.CheckBox 1.CheckBox的常用方法: boolean isChecked() :返回当前CheckBox的选中状态 void setChecked(boolean isChecked ...
- C++ 引用、指针
一.引用 1.引用的作用:给变量起一个别名,是c++对c的扩充.原名和别名有相同的地址,根本上就是同一个东西,只是名字不一样.c++的引用机制主要是为了用作函数参数,增强函数传递数据的能力,比如swa ...
- Linux——网络编程线程池机制
#include <stdlib.h>#include <pthread.h>#include <unistd.h>#include <assert.h> ...
- Java8新特性 Stream流式思想(三)
Stream接口中的常用方法 forEach()方法package cn.com.cqucc.demo02.StreamMethods.Test02.StreamMethods; import jav ...
- fedora安装gcc
查看gcc版本 gcc --version 命令行编译 g++ -std=c++11 -o main main.cpp 查看程序是否编译成功 echo $? 返回0表示编译成功 新版的Fedora(2 ...
- VS2008 ActiveX(ocx控件)的调试工具ActiveX Control Test Container安装说明
vs2008中的TSTCON( ActiveX Control Test Container )工具非自动安装,而是作为一个例程提供.所以应找到该例程,并编译: 如vs2008安装在默认路径则 1, ...