🧩PS/🥈Nomal
[C/C++] 백준 12871번 - 무한 문자열
Cocoon_
2021. 4. 4. 01:32
반응형
<코드>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
string s, t, fs, ft;
// 최대공약수 구하기
int GCD(int a, int b)
{
if (b == 0) {
return a;
}
else {
return GCD(b, a % b);
}
}
// 최소공배수 구하기
int LCM(int a, int b)
{
return a * b / GCD(a, b);
}
int main()
{
cin >> s >> t;
int tmp = LCM(s.size(), t.size());
for (int i = 0; i < tmp / s.size(); i++)
fs += s;
for (int i = 0; i < tmp / t.size(); i++)
ft += t;
if (fs == ft) cout << 1 << '\n';
else cout << 0 << '\n';
}
12871번: 무한 문자열
첫째 줄에 s, 둘째 줄에 t가 주어진다. 두 문자열 s와 t의 길이는 50보다 작거나 같은 자연수이고, 알파벳 소문자로만 이루어져 있다.
www.acmicpc.net
반응형