取余for循环

博约8486  •  1个月前


include<bits/stdc++.h>

using namespace std; int main(){

string s1, s2;
cin >> s1 >> s2;
if(s1 == s2) {
	cout << 0;
	return 0;
}
for(int i = 1; i <= s1.length(); i++){
	string s3 = "";
	for(int j = 0; j < s1.length(); j++){
		int index = (i + j) % s1.length();
		s3 = s3 + s1[index];
	} 

// cout << s3 << endl;

	if(s3 == s2) {
		cout << i;
		return 0;
	}
}

}


评论:

请先登录,才能进行评论