CF 798B 渣渣题

题目链接:http://codeforces.com/contest/798/problem/B

 

此题是我打河工大校赛前一晚熬夜打CF时硬肛过去的B题,今天补题时,偶然看到dalao的代码,ORZ,string和find函数的用法学到了。啦啦啦

虽然,那天现场赛炸了,但并不影响我的可爱呀,略略略!!

 1 #include<string>
 2 #include<cstdio>
 3 #include<iostream>
 4 using namespace std;
 5 int main()
 6 {
 7     string  temp,ch[55];
 8     int n,ans=0x3f3f3f3f,count=0;
 9     cin>>n;
10     for(int i=0;i<n;i++)  cin>>ch[i];
11     for(int i=0;i<n;i++)
12     {
13         count=0;
14         for(int j=0;j<n;j++)  
15         {
16             temp=ch[j]+ch[j];        //如果要处理首尾,循环的问题,再加一次是很好的选择
17 16             //如果发现不了这样的字符串,这个find会等于string::npos(可以看作的很大的数 ) 
18             if(temp.find(ch[i])==string::npos)  
19             {
20                 printf("-1\n"); return 0;
21             }
22             count+=temp.find(ch[i]);  //发现相同字符串的头位置
23         }
24         ans=min(ans,count);
25     }
26     printf("%d\n",ans);
27     return 0;
28 }

 

posted on 2017-05-04 19:45  欲儿很轻狂  阅读(205)  评论(0编辑  收藏  举报

导航