Codeforces 479【B】div3

题目链接: http://codeforces.com/problemset/problem/977/B

题意:字符串,找固定长度为2的重复子串出现次数最多的。

题解:我暴力做的。暴力出奇迹。

 1 #include<iostream>
 2 using namespace std;
 3 #define maxn 105
 4 
 5 char a[maxn];
 6 int main(){
 7     int n;
 8     cin>>n;
 9     for(int i = 0; i < n ;i++){
10         cin>>a[i];
11     }
12     int max = 0;
13     int maxi;
14     int cnt = 0;
15     for(int i = 0; i < n ;i++){
16         cnt = 0;
17         for(int j = i+1 ; j < n ;j++){
18             
19             if(a[i] == a[j] && a[i+1] == a[j+1]){
20                 cnt++;
21             }
22         }
23         if(cnt > max){
24             max = cnt;
25             maxi = i;
26         }
27     }
28     
29     cout<<a[maxi]<<a[maxi+1]<<endl;
30 
31     
32     
33     return 0;
34 }
View Code

猜你喜欢

转载自www.cnblogs.com/Asumi/p/9005499.html