校赛 选修课网址 1096: Is The Same?(kmp或者find)
来源:互联网 发布:python 网络数据采集 编辑:程序博客网 时间:2024/06/08 03:11
1096: Is The Same?
Time Limit: 1 Sec Memory Limit: 64 MB
Submit: 30 Solved: 11
[Submit][Status][Web Board]
Description
给出2个字符串S和T,如果可以通过循环移位使得S和T相等,则我们称S和T是同构字符串, 例如S=“abcd”, T=“bcda”,则S和T是同构字符串;而S=“abcd”和T=“bcad”则不是同构字符串。
循环移位是指:在⼀个长度为n的字符串S中,取⼀个任意下标i,把字符串分为两段,分别为 S1S2...Si 和Si+1Si+2...Sn,然后把字符串变为Si+1Si+2...SnS1S2...Si,例如S=“qwerty”,取i=3, 则变 为”rtyqwe”(注意,一个字符串本⾝身也算是它的同构字符串)。
Input
第⼀行包含一个整数T(1 <= T <= 20),代表测试组数。
对于每组数据,包含2个字符串,字符串长度都小于等于105且非空,输入保证字符串只包含小写字⺟。
Output
对于每组数据,如果这两个字符串是同构字符串,则输出Yes,否则输出No。
Sample Input
2
abcd
bcda
abcd
bcad
Sample Output
Yes
No
HINT
Source
Time Limit: 1 Sec Memory Limit: 64 MB
Submit: 30 Solved: 11
[Submit][Status][Web Board]
Description
给出2个字符串S和T,如果可以通过循环移位使得S和T相等,则我们称S和T是同构字符串, 例如S=“abcd”, T=“bcda”,则S和T是同构字符串;而S=“abcd”和T=“bcad”则不是同构字符串。
循环移位是指:在⼀个长度为n的字符串S中,取⼀个任意下标i,把字符串分为两段,分别为 S1S2...Si 和Si+1Si+2...Sn,然后把字符串变为Si+1Si+2...SnS1S2...Si,例如S=“qwerty”,取i=3, 则变 为”rtyqwe”(注意,一个字符串本⾝身也算是它的同构字符串)。
Input
第⼀行包含一个整数T(1 <= T <= 20),代表测试组数。
对于每组数据,包含2个字符串,字符串长度都小于等于105且非空,输入保证字符串只包含小写字⺟。
Output
对于每组数据,如果这两个字符串是同构字符串,则输出Yes,否则输出No。
Sample Input
2
abcd
bcda
abcd
bcad
Sample Output
Yes
No
HINT
Source
Alex@NBUT
将原字符串m重复两次 在新的字符串中查找是否有n 就像一串珠子 与边上的珠子都相对确定
#include<iostream>#include<cstring>#include<string>#include<sstream>#include<algorithm>using namespace std;int main(){string n,m,nn,mm;long long a,b,i,k;cin>>a;while(a--){cin>>n>>m;k=5;if(n.size()!=m.size()){k=0;}nn=n+n;mm=m+m;if((nn.find(m)!=string::npos||mm.find(n)!=string::npos)&&k)cout<<"Yes"<<endl;else cout<<"No"<<endl; mm="";nn="";}return 0;}/*kmp#include<iostream>#include<string>#include<cstring>using namespace std;int nexta[1000100];void getnext(string n){int i=0,j=-1;nexta[0]=-1;while(i<n.size()){if(j==-1||n[i]==n[j]){++i;++j;nexta[i]=j;}else j=nexta[j];}}long long kmp(string n,string m){int i=0,j=0;while(i<n.size()){if(j==-1||n[i]==m[j]){++i;++j;}else j=nexta[j];if(j==m.size()){return 3;}}return 0;}int main(){string n,m,nn,mm;long long a,b,c,i,d,k;cin>>a;while(a--){memset(nexta,0,sizeof(nexta));k=5;cin>>n>>m;nn=n+n;if(n.size()!=m.size()){k=0;}getnext(m);if(kmp(nn,m)&&k){cout<<"Yes"<<endl;}else cout<<"No"<<endl;} return 0;}*/
0 0
- 校赛 选修课网址 1096: Is The Same?(kmp或者find)
- 校赛——1096Is The Same?(KMP或字符串的最小、大表示法)
- 校赛 选修课网址 1097: Meeting
- 选修课网址 1088: The Owl and the Fox
- FWNX - find the same father - TREE
- Find the Shortest Common Superstring(hdu1841,KMP)
- 题目1841 Find the Shortest Common Superstring(KMP)
- HDOJ 1841 Find the Shortest Common Superstring(KMP)
- HDU 1841 Find the Shortest Common Superstring(KMP)
- hdu1841 Find the Shortest Common Superstring-----KMP
- find the two same numbers in 1 million random numbers
- Struct is the same as int and float
- chaussure tn pas cher moving people is the same ah
- java.io.IOException: The same input jar is specified twice.
- java.io.IOException: The same input jar is specified twice”
- Android Studio 'The same input jar is specified twice'
- The same input jar ***.jar is specified twice
- The same input jar is specified twice 解决办法
- Android 开源之StickyHeaderListView 标题渐变、吸附悬停、筛选分类、动态头部
- 算法实现之交换排序——冒泡与快排
- 关于MyElipse tomcat部署成功,却无法添加到webapps的问题
- 解决java compiler level does not match the version of the installed java project facet
- 我就是我......
- 校赛 选修课网址 1096: Is The Same?(kmp或者find)
- Android版本号对应关系
- 构建BBB内核
- 《TCP/IP详解》学习笔记-第9/10章 IP选路&动态选路
- Mac OS X系统 HomeBrew的安装和简单使用
- HDU——1874畅通工程续(Dijkstra与SPFA)
- 进程相关的数据结构
- 设计模式之适配器
- [BZOJ1683][Usaco2005 Nov]City skyline 城市地平线(单调栈)