fork(6) download
  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4. #include <fstream>
  5. #include <sstream>
  6. #include <vector>
  7. #include <algorithm>
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.  
  13. int plen;
  14. string str;
  15. while( cin >> plen >> str)
  16. {
  17. int len = str.size();
  18. if( plen <= len )
  19. {
  20. map<string, long int> sub;
  21. for(int i = 0; i < len-plen+1; ++i)
  22. {
  23. sub[str.substr(i, plen)]++;
  24. }
  25. map<string, long int>::iterator it;
  26. long int max = 0;
  27. string pass;
  28. for(it = sub.begin(); it != sub.end(); ++it)
  29. {
  30. if(it->second > max)
  31. {
  32. max = it->second;
  33. pass = it->first;
  34. }
  35. }
  36. cout << pass << endl;
  37. sub.clear();
  38. }
  39.  
  40. str.clear();
  41. }
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0s 3040KB
stdin
6 aba
2 aba
1 thequickbrownfoxjumpsoverthelazydog
3 thequickbrownfoxjumpsoverthelazydog
4 testingthecodetofindtheerrortestandtestagain
5 thearraycanbetoobigsobecarefulandtherecantberarecasescanbe
2 ababa
2 babab
1 ab
1 a
stdout
ab
o
the
test
canbe
ab
ab
a
a