M - String LCM(LCM字符串)

Let’s define a multiplication operation between a string aa and a positive integer xx: a⋅xa⋅x is the string that is a result of writing xx copies of aa one after another. For example, “abc” ⋅ 2 =⋅ 2 = “abcabc”, “a” ⋅ 5 =⋅ 5 = “aaaaa”.

A string aa is divisible by another string bb if there exists an integer xx such that b⋅x=ab⋅x=a. For example, “abababab” is divisible by “ab”, but is not divisible by “ababab” or “aa”.

LCM of two strings ss and tt (defined as LCM(s,t)LCM(s,t)) is the shortest non-empty string that is divisible by both ss and tt.

You are given two strings ss and tt. Find LCM(s,t)LCM(s,t) or report that it does not exist. It can be shown that if LCM(s,t)LCM(s,t) exists, it is unique.

Input
The first line contains one integer qq (1≤q≤20001≤q≤2000) — the number of test cases.

Each test case consists of two lines, containing strings ss and tt (1≤|s|,|t|≤201≤|s|,|t|≤20). Each character in each of these strings is either ‘a’ or ‘b’.

Output
For each test case, print LCM(s,t)LCM(s,t) if it exists; otherwise, print -1. It can be shown that if LCM(s,t)LCM(s,t) exists, it is unique.

Example
Input
3
baba
ba
aa
aaa
aba
ab
Output
baba
aaaaaa
-1
Note
In the first test case, “baba” = “baba” ⋅ 1 =⋅ 1 = “ba” ⋅ 2⋅ 2.

In the second test case, “aaaaaa” = “aa” ⋅ 3 =⋅ 3 = “aaa” ⋅ 2⋅ 2.

#include<bits/stdc++.h>
using namespace std; 
int main()
{
	int i,t,x,y,s,c,f,d,v,n;
	char a[100],b[100];
	scanf("%d",&n);
	getchar();
	while(n--)
	{
		gets(a);
		gets(b);
		x=strlen(a);
		y=strlen(b);
		s=x;f=y;
		if(x<y)
		{
			t=x;
			x=y;
			y=t;
		}
		c=x%y;
		while(c!=0)
		{
			x=y;
			y=c;
			c=x%y;
		}
		d=y;
		v=s/d*f;//求最小公倍数 
		int k=0;
		for(i=0;i<v;i++)
		{
			if(a[i%s]!=b[i%f])
			{
				k=1;
				break;
			}
		} 
		if(k)
		printf("-1\n");
		else
		{
			for(i=0;i<v;i++)
			printf("%c",a[i%s]);
			printf("\n");
		}
	}
	return 0;
}
。打开功能是专门用于对C语言文件自动提取显示所需要的汉字,进行点阵码数据转换的, 在您的C语言程序中,有一点需要特别留意:您的注解中请不要使用双引号,否则会引起 提取错误。 软件包中的文件ee.c作为一个简单例程供提取测试用。 2。提取以后的点阵码可以随意修改点阵数据,使用鼠标的左键为加一点,右键为擦除一点。 修改完毕请按旁边的确认键将数据记录到点阵码中,否则您的修改将自动放弃。 3。点阵码可以随意平移,请谨慎使用。平移之前请查看一遍所有的字符点阵图,平移有可能 会丢失边界点,移出了边界的点阵将被丢弃,不可恢复。 平移前请确认是否有必要进行全体字符一起移动。 4。用户自定义特殊字符的建立,首先选定点阵数据,在下面的汉字输入窗口输入几个您不使 用的汉字,确认。然后生成了这些汉字的点阵码,再将他们清空(使用平移按钮中间的那 块抹布),就可以用鼠标描绘你的图案了,最后别忘了打“确认”键。 5。ASCII字符可以自动提取0x20~0x7f的全部,最后一个0x7f一般都没有用,可以手工将它删 除,也可以利用它做一个简单的特殊字符。 汉字库中也包含有ascii字符,但是经查对与这三个ascii库基本一样,所以就不再重复。 6。保存文件:C语言格式的默认为.h类型,汇编格式的默认为.inc类型,只要将他们加入到 您的工程中就可以了。 7。新增加了自动添加下划线功能。这项功能在做点阵显示和修改的时候并不出现下划线, 设置了以后仅仅在最后的输出文件中出现,以免干扰编辑修改。 8。扩充对windows汉字的直接提取,从16~96范围内可以任意设定选取。主要用于制作界面的 开机封面少量标识性汉字。 9。扩充了对ascii小字库5x8以及大字库20*40/24*48的支持,毕竟字库文件比较工整。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值