/***
Md. Namzul Hasan
Shahjalal University of Science & technology,sylhet.
hasan08sust@gmail.com
Problem id : 10132
verdict:
***/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cctype>
#include<sstream>
#include<stdlib.h>
#include<map>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
string str[100] ;
map<string,in> mp ;
map<string, in> :: iterator it ;
int main()
{
in test ;
cin>>test ;
char ch[500] ;
getchar() ;
gets(ch) ;
while(test--)
{
in k=0 ;
while(gets(ch))
{
if(ch[0]==NULL)
break ;
str[k++] = ch ;
}
in minimum = 10000 , maximum =0 ;
for(in i=0 ; i<k ; i++)
{
if(minimum>str[i].size())
minimum = str[i].size() ;
if(maximum<str[i].size())
maximum = str[i].size() ;
}
mp.clear() ;
in len = maximum + minimum ;
for(in i=0 ; i<k ; i++)
{
for(in j=i+1 ; j<k ; j++)
{
string temp = str[i] + str[j] ;
if(len == temp.size())
{
it = mp.find(temp) ;
if(it!=mp.end())
mp[temp]++ ;
else
mp[temp] =1 ;
}
temp = str[j] + str[i] ;
if(len==temp.size())
{
it = mp.find(temp) ;
if(it!=mp.end())
mp[temp]++ ;
else
mp[temp] =1 ;
}
}
}
in t =0 ;
string ans ;
for(it = mp.begin() ; it!=mp.end() ; it++)
{
if(it->second > t)
{
t = it->second ;
ans = it-> first ;
}
}
cout<<ans<<endl ;
if(test)
pf("\n") ;
}
return 0 ;
}
Md. Namzul Hasan
Shahjalal University of Science & technology,sylhet.
hasan08sust@gmail.com
Problem id : 10132
verdict:
***/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cctype>
#include<sstream>
#include<stdlib.h>
#include<map>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
string str[100] ;
map<string,in> mp ;
map<string, in> :: iterator it ;
int main()
{
in test ;
cin>>test ;
char ch[500] ;
getchar() ;
gets(ch) ;
while(test--)
{
in k=0 ;
while(gets(ch))
{
if(ch[0]==NULL)
break ;
str[k++] = ch ;
}
in minimum = 10000 , maximum =0 ;
for(in i=0 ; i<k ; i++)
{
if(minimum>str[i].size())
minimum = str[i].size() ;
if(maximum<str[i].size())
maximum = str[i].size() ;
}
mp.clear() ;
in len = maximum + minimum ;
for(in i=0 ; i<k ; i++)
{
for(in j=i+1 ; j<k ; j++)
{
string temp = str[i] + str[j] ;
if(len == temp.size())
{
it = mp.find(temp) ;
if(it!=mp.end())
mp[temp]++ ;
else
mp[temp] =1 ;
}
temp = str[j] + str[i] ;
if(len==temp.size())
{
it = mp.find(temp) ;
if(it!=mp.end())
mp[temp]++ ;
else
mp[temp] =1 ;
}
}
}
in t =0 ;
string ans ;
for(it = mp.begin() ; it!=mp.end() ; it++)
{
if(it->second > t)
{
t = it->second ;
ans = it-> first ;
}
}
cout<<ans<<endl ;
if(test)
pf("\n") ;
}
return 0 ;
}
No comments:
Post a Comment