码迷,mamicode.com
首页 > 其他好文 > 详细

hdu1075

时间:2017-06-29 23:42:04      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:href   iostream   include   例子   cpp   etc   can   tar   stream   

链接:点击打开链接

题意:给出一句话依照密文所相应的原文输出应该输出的内容。详细看题目例子就能够

代码:

#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
char s[1000005][15];
char s1[3005];
int str[1000005][30],dis[1000005];
int root;
void in(char *s,int v){
    int u=0;
    for(;*s;s++){
        if(!str[u][*s-'a'])
        str[u][*s-'a']=root++;
        u=str[u][*s-'a'];
    }
    dis[u]=v;
}
int fi(char *s){
    int u=0;
    for(;*s;s++){
        if(!str[u][*s-'a'])
        return 0;
        u=str[u][*s-'a'];
    }
    return dis[u];
}                                        //字典树模板查找密文所相应的原文
int main(){
    char temp[3005];
    int i,j,len;
    memset(str,0,sizeof(str));
    memset(dis,0,sizeof(dis));
    memset(s,0,sizeof(s));
    scanf("%s",temp);
    i=root=1;
    while(1){
        scanf("%s",s[i]);                //用二维数组输入方便输出
        if(strcmp(s[i],"END")==0)
        break;
        scanf("%s",s1);
        in(s1,i);
        i++;
    }
    scanf("%s",temp);
    getchar();
    while(1){
        j=0;
        memset(s1,0,sizeof(s1));
        memset(temp,0,sizeof(temp));
        gets(s1);
        if(strcmp(s1,"END")==0)
        break;
//        len=strlen(s1);
//        if(s1[len-1]>='a'&&s1[len-1]<='z')
//        continue;
        for(i=0;s1[i];i++){             //这个题最关键的就是假如最后一个单词没有标点不输出最后一个单词。。

。 if(s1[i]>='a'&&s1[i]<='z') temp[j++]=s1[i]; else{ temp[j]='\0'; // cout<<temp<<endl; if(temp[0]!='\0'){ //这个就是将一句话中的单词拆出来 if(fi(temp)!=0) printf("%s",s[fi(temp)]); else printf("%s",temp); temp[0]='\0'; //将头变成'\0'就可以 j=0; } printf("%c",s1[i]); } // if(s1[i]=='\0') // break; } printf("\n"); } return 0; }


hdu1075

标签:href   iostream   include   例子   cpp   etc   can   tar   stream   

原文地址:http://www.cnblogs.com/gavanwanggw/p/7096573.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!