题目链接:http://poj.org/problem?id=1318

/*题意:在字母乱序的单词里面找到字母相同的字典里面的单词*/

/*此题的主要思路是要将字符排序,然后找对应,如果相同,那么就将此按字典序将字母一样的单词输出,
本人觉得此题的关键的问题是要将字符排序,那么就会出现二维字符数组的排序问题,
二维字符数组排序有很多种方法(因为二维字符数组不能直接复制,所以不能直接用sort()排序),
1.可以用到结构体
2.指针
3.可以将二维的字符数组转化成一维的字符数组(以下代码就是用的这种方法)
代码优化:将待确定的字符直接用一维的字符数组,然后排序,直接与第一部分的单词相比较
*/

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
char str1[][],str2[][];
char tra1[][],tra2[][];
char temp[]; int cmp(const void *a,const void *b)
{
return(strcmp((char*)a,(char*)b));
} int main(){
int len1=,len2=; //计算str1与str2的长度
for(int i=;i<;i++){
cin>>str1[i];
if(str1[i][]=='X'){
break;
}
len1++;
}
qsort(str1,len1,sizeof(str1[]),cmp);
for(int i=;i<len1;i++){
strcpy(tra1[i],str1[i]); //复制
}
for(int i=;i<;i++){
cin>>str2[i];
strcpy(tra2[i],str2[i]); //复制
if(str2[i][]=='X'){
break;
}
len2++;
}
//将字符按照asc码的形式进行排序 for(int i=;i<len1;i++){
int len3=strlen(str1[i]);
strcpy(temp,tra1[i]);
sort(temp,temp+len3);
strcpy(tra1[i],temp);
// cout<<tra1[i]<<endl;
}
for(int i=;i<len2;i++){
int len4=strlen(str2[i]);
strcpy(temp,tra2[i]);
sort(temp,temp+len4);
strcpy(tra2[i],temp); }
//比较字符串是否相同
int num;
for(int i=;i<len2;i++){
num=;
for(int j=;j<len1;j++){
if(strcmp(tra2[i],tra1[j])==){
cout<<str1[j]<<endl;
num++;
}
if(j==len1-){
if(num==){
printf("NOT A VALID WORD\n");
}
printf("******\n");
}
}
}
return ;
}

poj 1318Word Amalgamation的更多相关文章

  1. poj 1318 Word Amalgamation

    Word Amalgamation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9968   Accepted: 4774 ...

  2. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  3. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  4. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  5. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  6. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  7. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  8. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  9. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

随机推荐

  1. Codeforces 376B. Coupons and Discounts

    B. Coupons and Discounts time limit per test 1 second memory limit per test 256 megabytes input stan ...

  2. ⒂bootstrap组件 折叠 基础案例

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. lvs学习笔记

    本人身为一个网工,最近一直在工作中学习linux的相关知识.前短时间通过自查资料学习了lvs的相关内容,摘录部分整理后和大家分享,内容较多,较琐碎,望见谅!!! LVS 从Linux内核版本2.6起, ...

  4. Scrum Meeting Alpha - 6

    Scrum Meeting Alpha - 6 NewTeam 2017/10/31 地点:主南203 任务反馈 团队成员 完成任务 计划任务 安万贺 完成了个人博客和班级列表部分API的包装 完成个 ...

  5. C#去掉字符串头尾指定字符

    private void button2_Click(object sender, EventArgs e)        {//去掉字符串头尾指定字符            string MyInf ...

  6. .Net主线程扑捉子线程中的异常

    首先看一段C#代码:运行后发现主线程通过try{}catch{}是不能扑捉子线程中的抛出来的异常. 代码 );        }        public void run()        {   ...

  7. PowerShell安全修改Windows 10 登陆背景图

    PowerShell安全修改Windows 10 登陆背景图 可以把登陆的背景图换掉,主要是修改操作pri文件 $priPath = "$env:windir\SystemResources ...

  8. Java多线程学习之ThreadLocal源码分析

    0.概述 ThreadLocal,即线程本地变量,是一个以ThreadLocal对象为键.任意对象为值的存储结构.它可以将变量绑定到特定的线程上,使每个线程都拥有改变量的一个拷贝,各线程相同变量间互不 ...

  9. mybatis逆向工程之生成文件解释

    一.mapper接口中的方法解析 mapper接口中的函数及方法 方法 功能说明 int countByExample(UserExample example) thorws SQLException ...

  10. 一、Hadoop学习笔记————概述

    hadoop使用java编写,版本较为混乱,初学者可从1.2.1开始学习