公式
C - Vertical Reading 解説 by en_translator
Enumerate all possible \(c\) and \(w\), and determine if a conforming pair \(c,w\) exists.
One can construct a string for \(c\) and \(w\) using a for statement and concatenation of strings. For more details, please refer to the sample code.
Sample code (C++):
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
for (int w = 1; w < (int)s.size(); ++w) {
for (int c = 0; c < w; ++c) {
string now = "";
for (int i = c; i < (int)s.size(); i += w) {
now += s[i];
}
if (now == t) {
cout << "Yes" << endl;
return 0;
}
}
}
cout << "No" << endl;
}
投稿日時:
最終更新: