# Vijos1382 寻找主人

## 又是一道最小表示法模板题

Posted by yjjr's blog on January 15, 2018

# 题目

2234342423 2423223434

Yes 2234342423

NOI2008模拟 郭华阳

# code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
{
ll f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int maxn=3e6+6;
char st1[maxn],st2[maxn];
int len;

int find(char *st){
int i=0,j=1,k;
while(i<len&&j<len){
k=0;while(k<len&&st[(k+i)%len]==st[(k+j)%len])k++;
if(k==len)return i;
if(st[(i+k)%len]>st[(j+k)%len])i+=k+1;else j+=k+1;
if(i==j)j++;
}
return min(i,j);
}
int main()
{
scanf("%s",st1);scanf("%s",st2);
len=strlen(st1);
int pos1=find(st1),pos2=find(st2);
for(int i=0;i<len;i++)
if(st1[(pos1+i)%len]!=st2[(pos2+i)%len]){puts("No");return 0;}
puts("Yes");
for(int i=0;i<len;i++)printf("%c",st1[(pos1+i)%len]);
return 0;
}