usaco3.14Contact(STL)
又从cuishen 那学了新东西。。map是可以输出的。。还有这个字符串的输入方式挺高端的 学习了。。之后就是暴力枚举就行了
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 /* 2 ID: shangca2 3 LANG: C++ 4 TASK: contact 5 */ 6 #include <iostream> 7 #include<cstdio> 8 #include<cstring> 9 #include<algorithm> 10 #include<stdlib.h> 11 #include<cmath> 12 #include<map> 13 #include<queue> 14 using namespace std; 15 map<string,int>f; 16 map<string,int>::iterator it; 17 char str[200010],s[20]; 18 string p[1010]; 19 bool cmp(string a,string b) 20 { 21 if(a.length()==b.length()) 22 return a<b; 23 return a.length()<b.length(); 24 } 25 int main() 26 { 27 freopen("contact.in","r",stdin); 28 freopen("contact.out","w",stdout); 29 int i,j,k,n,a,b,g=0; 30 cin>>a>>b>>n; 31 char c; 32 i=0; 33 while(scanf("%s",str+i) == 1) 34 { 35 i += strlen(str+i); 36 } 37 g = strlen(str); 38 for(i = 0 ; i < g ; i++) 39 { 40 int o=0; 41 for(j = i ; j < i+b && j<g; j++) 42 { 43 s[o++] = str[j]; 44 if(o>=a) 45 { 46 s[o] = '\0'; 47 f[s]++; 48 } 49 } 50 } 51 for(i = 1; i <= n ; i++) 52 { 53 int o = 0; 54 for(it = f.begin() ; it != f.end() ; it++) 55 { 56 if(o<(*it).second) 57 o = (*it).second; 58 } 59 if(o==0) 60 break; 61 int num=0; 62 cout<<o<<endl; 63 for(it = f.begin() ; it != f.end() ; it++) 64 { 65 if(o==(*it).second) 66 { 67 p[++num] = (*it).first; 68 (*it).second = 0; 69 } 70 } 71 sort(p+1,p+num+1,cmp); 72 for(j = 1 ; j <= num ; j++) 73 { 74 if(j%6!=1) 75 cout<<" "; 76 cout<<p[j]; 77 if(j%6==0) 78 puts(""); 79 } 80 if(num%6!=0) 81 puts(""); 82 } 83 return 0; 84 }