# Include <iostream> # include <cstdio> # include <string> # include <cstring> # include <vector> # include <map> using namespace STD; int main () {int N; Map <string, int> m; vector <string> Sv; scanf ("% d \ n", & N); While (n --) {Sv. clear (); M. clear (); string s; int sum = 0; while (Getline (CIN, S), S. size ()> 0) {Sv. push_back (s); sum + = S. size ();} int Len = sum/(Sv. size ()/2); For (size_t I = 0; I <SV. size ()-1; I ++) for (size_t J = I + 1; j <SV. size (); j ++) if (SV [I]. size () + SV [J]. size () = Len) {string n = SV [I] + SV [J]; If (M. count (n)> 0) m [N] ++; else M [N] = 1; n = SV [J] + SV [I]; If (M. count (n)> 0) m [N] ++; else M [N] = 1;} string file; int max =-1; Map <string, int> :: iterator it; for (IT = m. begin (); it! = M. end (); It ++) if (* it ). second> MAX) {file = (* it ). first; max = (* it ). second;} cout <file <Endl; If (n! = 0) cout <Endl;} return 0 ;}
10132-file fragmentation
solution Report: Calculate the result length Len based on the input, and combine any two fragments to make the result equal to Len and put it in map. Finally, traverse the map and output the maximum value!