hdu1247 Hat’s Words 字符串模拟

本文提供了一种解决hdu1247 Hat's Words问题的方法,通过字符串模拟技术来检查字符串是否可以被正确分割,并判断分割后的两部分是否独立存在于输入数据中。

  将每个字符串分割,查找,如果分割后的2个字符串均存在的话输出这个字符串。墨迹了一些。

 1 #include <map>
 2 #include <string>
 3 #include <iostream>
 4 using namespace std;
 5 int main()
 6 {
 7     string temp;
 8     string a[50000+10];
 9     string t1,t2;
10     int l;
11     map<string,int>haha;
12     int k,i,j,q,cnt=0;
13     while(cin>>temp)
14     {
15         haha[temp]++;
16         a[cnt++]=temp;
17     }
18     for(k=0;k<cnt;++k)
19     {
20         l=a[k].length();
21         if(l==1)
22           continue;
23         //把temp分成2部分,一部分长度是1~L-1,另一部分就是剩下的
24         for(i=1;i<=l-1;++i)
25         {
26             t1="0";
27             t2="0";
28             for(j=1;j<i;++j)
29              t1=t1+"0";
30             for(j=1;j<l-i;++j)
31              t2=t2+"0";
32             for(j=0;j<i;++j)
33             {
34                 t1[j]=a[k][j];
35             }
36             for(j=i,q=0;j<l;++j,++q)
37             {
38                 t2[q]=a[k][j];
39             }
40             if(haha[t1]&&haha[t2])
41             {
42                 cout<<a[k]<<endl;
43                 break;
44             }
45         }
46     }
47     return 0;
48 
49 }

 

posted on 2013-03-02 12:40 symons 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/symons1992/archive/2013/03/02/2939924.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值