https://i2.wp.com/eblogarithm.com/wp-content/uploads/2017/07/Codeforces-Round-410-Div-2-problem-B-Mike-and-strings-Solution-In-CC1.png?fit=640%2C360

Codeforces Round #410 (Div. 2), problem: (B) Mike and strings Solution In C/C++

#include <bits/stdc++.h>
using namespace std;
string s[51];

int main()
{
int n, t, ans;
ans = INT_MAX;
cin>>n;
string temp;
for(int i=0; i<n; i++)
cin>>s[i];
for(int i=0; i<n; i++)
{
t = 0;
for(int j=0; j<n; j++)
{
temp=s[j]+s[j];
if(temp.find(s[i])==string::npos)
{
cout<<-1<<endl;
return 0;
}
t += temp.find(s[i]);
}
ans = t<ans?t:ans;
}
cout<<ans;
return 0;
}

(Visited 58 times, 1 visits today)



There are no comments

Add yours

Leave a Reply

%d bloggers like this: