text stringlengths 49 983k |
|---|
#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
int main() {
ios::sync_with_stdio(0);
string s;
int n;
cin >> n;
cin >> s;
for (int i = 0; i < ((int)(s).size()) - 1; i++) m[s.substr(i, 2)]++;
string w;
int k = 0;
for (auto o : m) {
if (o.second >= k) {
k = o.second;
w = o.first;
}
}
cout << w;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
map<string, int> a;
string b, c;
int n;
void work(void) {
map<string, int>::iterator p;
int i, t;
t = 0;
for (i = 0; i <= n - 2; i++) {
c = b[i];
c += b[i + 1];
a[c]++;
}
for (p = a.begin(); p != a.end(); p++)
if (p->second > t) {
t = p->second;
c = p->first;
}
cout << c;
}
int main(void) {
cin >> n;
cin >> b;
work();
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int n, i, j, count = 0, max = 0;
char str[100], a[3];
scanf("%d", &n);
getchar();
gets(str);
for (i = 1; i < n; i++) {
count = 1;
for (j = i + 1; j < n; j++) {
if (str[i - 1] == str[j - 1] && str[i] == str[j]) {
count++;
}
}
if (count > max) {
max = count;
a[0] = str[i - 1];
a[1] = str[i];
a[2] = '\0';
}
}
puts(a);
}
|
#include <bits/stdc++.h>
int main() {
int n, k = 0, m = 0;
scanf("%d", &n);
char s[n], a, b;
scanf("%s", s);
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - 1; j++) {
if (s[j] == s[i] && s[j + 1] == s[i + 1]) {
k++;
}
}
if (m < k) {
m = k;
a = s[i];
b = s[i + 1];
}
k = 0;
}
printf("%c%c\n", a, b);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
map<string, int> m;
string x, cmp = "11";
cin >> n >> x;
for (int i = 0; i < n - 1; i++) {
cmp[0] = x[i];
cmp[1] = x[i + 1];
m[cmp]++;
}
string ans = "";
int may = -1;
for (auto i = m.begin(); i != m.end(); i++) {
if (i->second > may) {
may = i->second;
ans = i->first;
}
}
cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, maxi(0), m;
string s, now = "", ans = "";
cin >> m >> s;
map<string, int> mp;
n = s.size();
for (int i = 0; i < n - 1; i++) {
now = s.substr(i, 2);
mp[now]++;
}
map<string, int>::iterator it;
for (it = mp.begin(); it != mp.end(); it++) {
if (it->second > maxi) {
maxi = it->second;
ans = it->first;
}
}
cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (~scanf("%d", &n)) {
char s[105];
scanf("%s", s);
int ans = -1;
char ansa, ansb;
for (int i = 1; i < n; i++) {
char a = s[i - 1];
char b = s[i];
int m = 0;
for (int i = 1; i < n; i++) {
if (s[i - 1] == a && s[i] == b) {
m++;
}
}
if (m > ans) {
ans = m;
ansa = a;
ansb = b;
}
}
printf("%c%c\n", ansa, ansb);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
string s;
cin >> n >> s;
map<string, int> f;
for (int i = 0; i < n - 1; ++i) f[s.substr(i, 2)]++;
string ans;
int times = 0;
for (auto &x : f)
if (x.second > times) {
times = x.second;
ans = x.first;
}
cout << ans << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
long m[100000];
int main() {
long n, i;
string s;
cin >> n;
getline(cin, s);
getline(cin, s);
for (i = 0; i < n - 1; i++) {
long k = 26 * (s[i] - 'A') + (s[i + 1] - 'A');
m[k]++;
}
long max = 0;
long ans = 0;
for (i = 0; i < 26 * 26; i++) {
if (m[i] >= max) {
ans = i;
max = m[i];
}
}
cout << char(ans / 26 + 'A') << char(ans % 26 + 'A');
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[101][101];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, k, i, j, l;
char s[101];
cin >> n;
for (i = 0; i < n; i++) cin >> s[i];
int c = 0;
for (i = 0, j = 1; i < n - 1; i++, j++) {
a[s[i]][s[j]]++;
}
char s1, s2;
int mx = -10001;
for (i = 0; i <= 100; i++) {
for (j = 0; j < 100; j++) {
if (a[i][j] > mx) {
mx = a[i][j];
s1 = i;
s2 = j;
}
}
}
cout << s1 << s2;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int i, j, k, l, mx = 0, c = 0;
char x, y, p = s[0], q = s[1];
for (i = 1; i < n; i++) {
c = 0;
x = s[i - 1];
y = s[i];
for (j = i + 1; j < n; j++) {
if (s[j - 1] == x && s[j] == y) {
c++;
}
}
if (mx < c) {
mx = c;
p = x;
q = y;
}
}
cout << p << q;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
map<string, int> m;
for (int i = 0; i <= n - 2; i++) {
m[s.substr(i, 2)]++;
}
map<string, int>::iterator it = m.begin();
string ans;
int mx = 0;
for (; it != m.end(); it++) {
if (it->second > mx) {
ans = it->first;
mx = it->second;
}
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
map<string, int> m;
int groot = 0;
string p = "";
vector<string> vec;
for (int i = 1; i < s.size(); i++) {
p.push_back(s[i - 1]);
p.push_back(s[i]);
m[p]++;
groot = max(groot, m[p]);
vec.push_back(p);
p = "";
}
for (int i = 0; i < vec.size(); i++) {
if (m[vec[i]] == groot) {
cout << vec[i] << endl;
break;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, mx = 0;
string s, a, c;
map<string, int> m;
cin >> n >> s;
for (int i = 0; i < n - 1; i++) {
c = s[i];
c += s[i + 1];
m[c]++;
if (m[c] > mx) {
mx = m[c];
a = c;
}
}
cout << a;
}
|
#include <bits/stdc++.h>
using namespace std;
int check[260][260];
char a[110];
int main() {
int n;
scanf("%d", &n);
scanf("%s", a + 1);
for (int i = 1; i < n; i++) {
check[a[i] - 'A'][a[i + 1] - 'A']++;
}
int maxx = 0;
int ansi, ansj;
for (int i = 0; i < 26; i++) {
for (int j = 0; j < 26; j++) {
if (maxx < check[i][j]) {
maxx = check[i][j];
ansi = i;
ansj = j;
}
}
}
printf("%c%c", ansi + 'A', ansj + 'A');
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, cnt[30][30] = {0}, subcnt = 0, strf = 0, strl = 0;
string s;
cin >> n >> s;
for (int i = 0; i < n - 1; i++) {
int x = s[i] - 'A';
int y = s[i + 1] - 'A';
cnt[x][y]++;
}
for (int i = 0; i < 26; i++) {
for (int j = 0; j < 26; j++) {
if (cnt[i][j] > subcnt) {
strf = i;
strl = j;
subcnt = cnt[i][j];
}
}
}
printf("%c%c\n", strf + 'A', strl + 'A');
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
bool isprime(long long int n) {
if (n == 1) return false;
if (n == 2 || n == 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (long long int i = 5; i * i <= n; i += 6) {
if (n % i == 0 || n % (i + 2) == 0) return false;
}
return true;
}
long long int binpow(long long int x, long long int n) {
long long int res = 1;
while (n > 0) {
if (n & 1) {
res = res * x;
}
x = x * x;
n = n >> 1;
}
return res;
}
void solve() {
long long int n;
cin >> n;
string s;
cin >> s;
unordered_map<string, int> m;
for (int i = 0; i < s.size() - 1; i++) {
string l = "";
l += s[i];
l += +s[i + 1];
m[l]++;
}
int max = 0;
string t;
for (auto x : m) {
if (x.second > max) {
max = x.second;
t = x.first;
}
}
cout << t << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int test_cases = 1;
while (test_cases--) {
solve();
}
cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
<< "ms\n";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string str;
cin >> str;
int i, j, max = 0;
string ans;
ans[0] = str[0];
ans[1] = str[1];
for (i = 0; i < n; i++) {
int ch(0);
for (j = i + 1; j < n;) {
if (str[i] == str[j] && str[i + 1] == str[j + 1]) ch++;
j += 1;
}
if (max < ch) {
max = ch;
ans[0] = str[i];
ans[1] = str[i + 1];
}
}
cout << ans[0] << ans[1];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c, c1, c2 = -1;
string s, s1, s2, s3;
cin >> n >> s;
for (int i = 0; i < n; i++) {
s1 = s.substr(i, 2), c = 0;
for (int j = i; j < n; j++) {
s2 = s.substr(j, 2);
if (s1 == s2) c++;
}
if (c > c2) c2 = c, s3 = s1;
}
cout << s3 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, count = 0, max = 0;
char k[101], a, b;
cin >> n;
cin >> k;
for (int i = 1; i < n; ++i) {
for (int j = n - 1; j > 0; --j) {
if (k[j] == k[i] && k[j - 1] == k[i - 1]) count++;
if (count > max) {
max = count;
a = k[i - 1];
b = k[i];
}
}
count = 0;
}
cout << a << b;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
map<string, int> m;
map<string, int>::iterator it;
for (int i = 0; i < (n - 1); i++) {
string x = s.substr(i, 2);
it = m.find(x);
if (it == m.end())
m.insert({x, 1});
else
m[x]++;
}
string ans;
int max = 0;
for (it = m.begin(); it != m.end(); it++) {
if (it->second > max) {
ans = it->first;
max = it->second;
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)2e5 + 5;
int main() {
int n;
cin >> n;
string s;
cin >> s;
map<string, int> m;
for (int i = 0; i < n - 1; ++i) {
m[s.substr(i, 2)]++;
}
string ans;
int maximum = -1;
for (map<string, int>::iterator it = m.begin(); it != m.end(); ++it) {
if (it->second > maximum) {
maximum = it->second;
ans = it->first;
}
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 100;
pair<char, char> p[MAXN + 10];
int arr[MAXN + 10];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
string str;
cin >> str;
int _max = 0;
int ans = 0;
int j = 0;
for (int i = 0; i < n - 1; i++) {
bool b = true;
for (j = 0; j < i; j++) {
if (str[i] == p[j].first && str[i + 1] == p[j].second) {
b = false;
arr[j]++;
if (arr[j] > _max) {
_max = arr[j];
ans = j;
}
}
}
if (b) {
p[i].first = str[i];
p[i].second = str[i + 1];
}
}
cout << p[ans].first << p[ans].second << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int mx = 0;
char x, y;
for (char a = 'A'; a <= 'Z'; a++) {
for (char b = 'A'; b <= 'Z'; b++) {
int as = 0;
for (int i = 0; i < s.length() - 1; i++) {
if (s[i] == a && s[i + 1] == b) as++;
}
if (as > mx) {
mx = as;
x = a;
y = b;
}
}
}
cout << x << y << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, str;
int n, i, j, cnt = 0, ans;
cin >> n >> s;
for (i = 0; i < n - 1; i++) {
ans = 0;
for (j = i; j < n - 1; j++) {
if (s[j] == s[i] && s[j + 1] == s[i + 1]) ans++;
}
if (ans > cnt) {
cnt = ans;
str.clear();
str.push_back(s[i]);
str.push_back(s[i + 1]);
}
}
cout << str << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x7fffffff;
const int N = 3e5 + 10;
char s[N];
int a[100][100], res, n;
char x, y;
int main() {
scanf("%d", &n);
scanf("%s", s);
for (int i = 0; i < n - 1; i++) {
int j = i + 1;
a[s[i]][s[j]]++;
if (a[s[i]][s[j]] > res) {
res = a[s[i]][s[j]];
x = s[i], y = s[j];
}
}
printf("%c%c", x, y);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
map<string, int> mp;
map<string, int>::iterator it1;
string st = "";
for (int i = 0; i < s.size() - 1; i++) {
st += s[i];
st += s[i + 1];
if (mp.count(st) == 0) {
mp[st] = 1;
} else {
mp[st]++;
}
st = "";
}
int m = INT_MIN;
for (auto it = mp.begin(); it != mp.end(); it++) {
if (it->second > m) {
m = it->second;
it1 = it;
}
}
cout << it1->first << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
string s;
cin >> s;
map<string, long long int> m;
for (int i = 0; i < n - 1; i++) {
string t;
t.push_back(s[i]);
t.push_back(s[i + 1]);
m[t]++;
}
long long int mx = 0;
string g;
for (auto it = m.begin(); it != m.end(); it++) {
if (it->second > mx) {
mx = max(mx, it->second);
g = it->first;
}
}
cout << g;
}
|
#include <bits/stdc++.h>
using namespace std;
string s;
int call(string sub) {
int cnt = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == sub[0] and s[i + 1] == sub[1]) cnt++;
}
return cnt;
}
int main() {
int n, maxi = 0, res;
string sub, gram;
cin >> n >> s;
for (int i = 0; i < s.length() - 1; i++) {
sub = s.substr(i, 2);
int check = call(sub);
if (check > maxi) {
maxi = check;
gram = sub;
}
}
cout << gram << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
map<string, int> M;
map<string, int>::iterator it, it1;
for (int i = 1; i < n; i++) {
M[s.substr(i - 1, 2)]++;
}
int m = 0;
for (it = M.begin(); it != M.end(); it++) {
if ((*it).second > m) {
m = (*it).second;
it1 = it;
}
}
cout << (*it1).first << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
map<string, int> cnt;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
int n;
cin >> n;
string s;
cin >> s;
for (int i = 0; i + 1 < s.size(); ++i) {
string cur = "";
cur += s[i];
cur += s[i + 1];
cnt[cur]++;
}
auto it = cnt.begin();
string ans = (*it).first;
for (auto p : cnt) {
if (cnt[ans] < p.second) ans = p.first;
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int i, j, n, max = -1, count, a;
char c1, c2;
scanf("%d", &n);
char s[n];
scanf("%s", s);
for (i = 0; i < n - 1; i++) {
count = 0;
for (j = i + 1; j < n - 1; j++) {
if (s[j] == s[i]) {
if (s[j + 1] == s[i + 1]) count++;
}
}
if (count > max) {
max = count;
c1 = s[i];
c2 = s[i + 1];
}
}
printf("%c%c\n", c1, c2);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long a[1000006];
int main(int argc, char const *argv[]) {
string s;
int n;
cin >> n;
map<string, int> mp;
vector<string> v;
cin >> s;
for (int i = 1; i < n; i++) {
string temp = "";
temp += s[i - 1];
temp += s[i];
mp[temp]++;
v.push_back(temp);
}
int mx = 0;
string ans;
for (int i = 0; i < v.size(); i++) {
if (mp[v[i]] >= mx) {
ans = v[i];
mx = mp[v[i]];
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int max = 0;
int index = 0;
for (int i = 0; i < n - 2; i++) {
int count = 0;
for (int j = i + 1; j < n - 1; j++) {
if (s[j] == s[i] && s[j + 1] == s[i + 1]) {
count++;
}
}
if (count > max) {
max = count;
index = i;
}
}
cout << s[index] << s[index + 1];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int no, maxvar = INT_MIN, cnt = 0;
string s, s2;
cin >> no;
cin >> s;
for (int i = 0; i < s.length() - 1; i++) {
string s1 = s.substr(i, 2);
cnt = 0;
for (int j = 0; j < s.length() - 1; j++) {
if (s1[0] == s[j] && s1[1] == s[j + 1]) {
cnt++;
}
if (cnt > maxvar) {
maxvar = cnt;
s2 = s1;
}
}
}
cout << s2;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
string s;
cin >> s;
map<string, int> gram;
for (int i = 0; i < n - 1; i++) ++gram[s.substr(i, 2)];
int cnt = 0;
string ans = "";
for (auto e : gram)
if (e.second > cnt) cnt = e.second, ans = e.first;
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
string s, ans;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cin >> s;
bool flag = true;
int cnt = 0, max_cnt = 0;
for (int i = 0; i < n - 1; ++i) {
string sub = s.substr(i, 2);
cnt = 0;
for (int j = 0; j < n - 1; ++j) {
flag = true;
for (int k = 0; k < 2; ++k) {
if (sub[k] != s[j + k]) flag = false;
}
if (flag) ++cnt;
if (cnt > max_cnt) {
max_cnt = cnt;
ans = sub;
}
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i, j, k;
string str;
cin >> n;
long long int chars[n];
char c1, c2;
cin >> str;
for (i = 0; i < n; i++) chars[i] = str[i] - 'A';
long long int matrix[26][26];
memset(matrix, 0, sizeof matrix);
for (i = 0; i < n - 1; i++) {
matrix[chars[i]][chars[i + 1]]++;
}
k = 0;
for (i = 0; i < 26; i++) {
for (j = 0; j < 26; j++) {
if (k < matrix[i][j]) {
k = matrix[i][j];
c1 = i + 65;
c2 = j + 65;
}
}
}
cout << c1 << c2 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
string s, c, a;
int n, i, p;
int main() {
for (cin >> n >> s; i < n - 1; i++) {
c += s[i];
c += s[i + 1];
m[c]++;
if (p < m[c]) p = m[c], a = c;
c.clear();
}
cout << a;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int x;
cin >> x;
string a;
cin >> a;
int mx = 0;
char f = a[0], s = a[1];
for (int j = 0; j < x - 2; j++) {
int c = 0;
char ma = a[j], mb = a[j + 1];
for (int i = j + 1; i < x - 1; i++) {
if (ma == a[i] && mb == a[i + 1]) c++;
}
if (mx < c) {
mx = c;
f = ma;
s = mb;
}
}
cout << f << s << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s, s1;
map<string, int> make_pair;
cin >> s;
for (int i = 0; i < n - 1; i++) {
string a;
a.push_back(s[i]);
a.push_back(s[i + 1]);
make_pair[a]++;
}
int ma = 0;
for (auto& i : make_pair) {
if (i.second > ma) {
ma = i.second;
s1 = i.first;
}
}
cout << s1;
}
|
#include <bits/stdc++.h>
using namespace std;
unordered_map<string, int> mp;
int main() {
int n, k, m, x, max1 = 0, i;
string s, s1, ans = "";
string ch, ch1;
cin >> n;
cin >> s;
for (i = 0; i < n - 1; ++i) {
ch = s[i], ch1 = s[i + 1];
s1 = ch + ch1;
++mp[s1];
x = mp[s1];
if (max1 < x) {
ans = s1, max1 = x;
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int t, max = 0, i, j;
scanf("%d ", &t);
char a[t], s, c;
scanf("%s", a);
for (i = 0; i < t - 1; i++) {
int count = 0;
for (j = i + 1; j < t - 1; j++) {
if (a[i] == a[j]) {
if (a[i + 1] == a[j + 1]) count++;
}
}
if (max <= count) {
max = count;
s = a[i];
c = a[i + 1];
}
}
printf("%c%c", s, c);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
map<string, int> m;
for (int i = 0; i < n - 1; i++) {
string x;
x += s[i];
x += s[i + 1];
m[x]++;
}
int mm = INT_MIN;
string ans;
for (auto i : m) {
if (i.second > mm) {
mm = i.second;
ans = i.first;
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
int main() {
string s, x;
int n;
cin >> n;
cin >> s;
int maxim = -1;
int l = s.length();
for (int i = 0; i < l; i++) {
string p = s.substr(i, 2);
m[p]++;
if (m[p] > maxim) {
maxim = m[p];
x = p;
}
}
cout << x << endl;
m.clear();
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, mn = INT_MIN;
cin >> n;
string s;
cin >> s;
int len = s.size();
unordered_map<string, int> m;
unordered_map<string, int>::iterator it;
for (int i = 0; i < len - 1; i++) {
string sub = s.substr(i, 2);
m[sub]++;
mn = max(mn, m[sub]);
}
for (it = m.begin(); it != m.end(); it++) {
if (it->second == mn) {
cout << it->first << "\n";
return 0;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int best = 0;
string ans;
unordered_map<string, int> cnt;
for (int i = 0; i + 1 < n; i++) {
string tmp = s.substr(i, 2);
cnt[tmp]++;
if (cnt[tmp] > best) {
best = cnt[tmp];
ans = tmp;
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<string, int> &a, const pair<string, int> &b) {
return (a.second < b.second);
}
int check(vector<pair<string, int> > vec, string s, int x) {
for (int i = 0; i < vec.size(); i++) {
string s1 = "ab";
s1[0] = s[x];
s1[1] = s[x + 1];
if (s1 == vec[i].first) {
return i;
}
}
return -1;
}
int main() {
int n;
cin >> n;
string s;
cin >> s;
vector<pair<string, int> > vec;
for (int i = 0; i < n - 1; i++) {
int index = check(vec, s, i) + 1;
if (!index) {
string s1 = "ab";
s1[0] = s[i];
s1[1] = s[i + 1];
vec.push_back(make_pair(s1, 1));
} else
vec[index - 1].second++;
}
sort(vec.begin(), vec.end(), sortbysec);
cout << vec[vec.size() - 1].first;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, mx = 0;
string s;
pair<char, char> ans;
map<pair<char, char>, int> mp;
cin >> n >> s;
for (int i = 1; i < n; i++) {
pair<char, char> curr = make_pair(s[i - 1], s[i]);
mp[curr]++;
if (mp[curr] > mx) mx = mp[curr], ans = curr;
}
cout << ans.first << ans.second << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
string s;
cin.ignore();
cin >> s;
int x = 0, count = 0;
string ans = "";
for (int i = 0; i < (n - 1); ++i) {
string s1 = "";
s1 += s[i];
s1 += s[i + 1];
for (int j = 0; j < (n - 1); ++j) {
string s2 = "";
if (j != i) {
s2 += s[j];
s2 += s[j + 1];
}
if (s1 == s2) ++count;
}
if (x < count) {
x = count;
ans = s1;
} else if (x == count) {
if (s1 < ans) ans = s1;
}
count = 0;
}
if (ans == "") {
char min = s[0];
int index = 0;
for (int i = 0; i < n; ++i) {
if (min > s[i]) {
min = s[i];
index = i;
}
}
if (index != (n - 1)) {
ans += s[index];
ans += s[index + 1];
} else {
ans += s[index - 1];
ans += s[index];
}
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
solve();
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
int n;
cin >> n;
cin >> str;
map<string, int> mp;
string mxstr;
int mx = 0;
for (int i = 0; i < str.size() - 1; i++) {
string str1 = "";
str1 += str[i];
str1 += str[i + 1];
mp[str1]++;
if (mp[str1] > mx) {
mx = mp[str1];
mxstr = str1;
}
}
cout << mxstr << endl;
return 0;
}
|
#include <bits/stdc++.h>
void met(int n, char cad[]) {
int may = 0;
char x;
char y;
for (int i = 0; i < n - 1; i++) {
int cont = 0;
for (int j = 0; j < n - 1; j++) {
if (cad[i] == cad[j] && cad[i + 1] == cad[j + 1]) {
cont++;
}
}
if (cont > may) {
may = cont;
x = cad[i];
y = cad[i + 1];
}
}
printf("%c%c", x, y);
}
int main() {
char cad[150];
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf(" %c", &cad[i]);
}
met(n, cad);
return 0;
}
|
#include <bits/stdc++.h>
const long long INF = 2e18;
const long long N = 1e4 + 1;
const long long mod = 1e9;
const long double eps = 1E-7;
using namespace std;
int mx;
void solve() {
string s;
char a, b;
int k;
cin >> k;
cin >> s;
for (int i = 0; i < k - 1; ++i) {
int dx = 0;
for (int j = 0; j < k - 1; ++j) {
if (j == i) continue;
if (s[i] == s[j] && s[i + 1] == s[j + 1]) dx++;
}
if (dx >= mx) mx = dx, a = s[i], b = s[i + 1];
}
cout << a << b << endl;
}
bool mtest = false;
int main() {
ios_base::sync_with_stdio(0);
int TE = 1;
if (mtest) cin >> TE;
while (TE--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, cnt, mcnt = 0, i, j;
string s, s1 = "pi";
cin >> n;
cin >> s;
for (i = 0; i < n - 1; i++) {
cnt = 0;
for (j = 0; j < n - 1; j++) {
if (s[i] == s[j] && s[i + 1] == s[j + 1]) cnt++;
}
if (cnt > mcnt) {
mcnt = cnt;
s1 = string(1, s[i]) + string(1, s[i + 1]);
}
}
cout << s1;
}
|
#include <bits/stdc++.h>
using namespace std;
string a;
int maxn = -99999999;
int weizhi = -1;
int n;
int __find__(int x) {
int sum = 0;
for (int i = 0; i < a.size() - 1; i++) {
int j = i;
if (a[j] == a[x] && a[j + 1] == a[x + 1]) sum++;
}
return sum;
}
int main() {
cin >> n;
cin >> a;
for (int i = 0; i < a.size() - 1; i++) {
int tmp = __find__(i);
if (maxn < tmp) weizhi = i, maxn = tmp;
}
cout << a[weizhi] << a[weizhi + 1];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
string b;
unordered_map<string, int> wordFreq;
int max = 0;
string result;
for (int i = 0; i < n; i++) {
b += s[i];
b += s[i + 1];
b += " ";
}
stringstream a(b);
string word;
while (a >> word) {
wordFreq[word]++;
if (max < wordFreq[word]) {
max = wordFreq[word];
result = word;
}
}
cout << result;
}
|
#include <bits/stdc++.h>
using namespace std;
int N;
char s[10005];
int cnt;
char mch[100005];
int ans;
char ss[1005];
int main() {
int i, j, k;
cin >> N;
for (i = 1; i <= N; i++) {
cin >> s[i];
}
for (i = 1; i <= N - 1; i++) {
mch[++cnt] = s[i];
mch[++cnt] = s[i + 1];
}
for (i = 1; i <= cnt; i += 2) {
char ft = mch[i];
char lt = mch[i + 1];
int ret = 0;
for (j = 1; j < N; j++) {
if (s[j] == ft && s[j + 1] == lt) ret++;
}
if (ret > ans) {
ans = ret;
ss[0] = ft;
ss[1] = lt;
}
}
cout << ss[0] << ss[1] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b,
long long int m = 1000000007) {
if (b == 0) return 1;
if (b == 1) return a;
long long int c = power(a, b / 2, m);
if (b % 2 == 0) return ((c % m) * (c % m)) % m;
return ((((c % m) * (c % m)) % m) * (a % m)) % m;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int n, k, m, i, j, c = 0, cs = 0, t;
t = 1;
string s, p;
while (t--) {
cin >> n >> s;
unordered_map<string, long long int> mp;
for (long long int i = 0; i < n - 1; i++) {
p = s[i];
p += s[i + 1];
mp[p]++;
}
for (auto x : mp) c = max(c, x.second);
for (auto x : mp) {
if (c == x.second) {
cout << x.first;
return 0;
}
}
if (t != 0) cout << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int p[50][50], n;
char q[5000];
while (~scanf("%d", &n)) {
getchar();
scanf("%s", q);
memset(p, 0, sizeof(p));
for (int i = 0; i < n - 1; i++) {
p[q[i] - 'A'][q[i + 1] - 'A']++;
}
int maxa = 0;
int maxb = 0;
for (int i = 0; i < 26; i++) {
for (int j = 0; j < 26; j++) {
if (p[i][j] > p[maxa][maxb]) {
maxa = i;
maxb = j;
}
}
}
printf("%c%c\n", 'A' + maxa, 'A' + maxb);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
char a, b;
int count, mx = 0;
int i, j;
cin >> n;
cin >> s;
for (i = 0; i < n - 1; i++) {
count = 0;
for (j = 0; j < n - 1; j++) {
if (s[j] == s[i] && s[j + 1] == s[i + 1]) count++;
}
if (count > mx) {
mx = count;
a = s[i];
b = s[i + 1];
}
}
cout << a << b;
}
|
#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int main() {
char max_s[3], s1[3], s[110];
max_s[2] = s1[2] = 0;
int max_num = 0, n;
scanf("%d", &n);
scanf("%s", &s);
for (int i = 0; i < n - 1; i++) {
s1[0] = s[i];
s1[1] = s[i + 1];
mp[s1]++;
if (mp[s1] > max_num) {
max_num = mp[s1];
max_s[0] = s1[0];
max_s[1] = s1[1];
}
}
printf("%s", max_s);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (cin >> n) {
int map[30][30] = {0};
string s;
cin >> s;
int maxx = 0;
int maxs;
for (int i = 0; i < s.size() - 1; i++) {
map[s[i] - 'A'][s[i + 1] - 'A']++;
if (map[s[i] - 'A'][s[i + 1] - 'A'] > maxx) {
maxx = map[s[i] - 'A'][s[i + 1] - 'A'];
maxs = i;
}
}
cout << s[maxs] << s[maxs + 1] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans = 0;
string s, a;
cin >> n >> s;
map<string, int> mp;
for (int i = 1; i < n; i++) {
string t = s.substr(i - 1, 2);
if (mp.find(t) == mp.end())
mp[t] = 0;
else
mp[t] = mp[t] + 1;
if (ans <= mp[t]) {
ans = mp[t];
a = t;
}
}
cout << a << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string s;
int call(string sub) {
int cnt = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == sub[0] and s[i + 1] == sub[1]) cnt++;
}
return cnt;
}
int main() {
int n, maxi = 0, res;
string sub, gram;
cin >> n >> s;
for (int i = 0; i < s.length() - 1; i++) {
sub = s.substr(i, 2);
int check = call(sub);
if (check > maxi) {
maxi = check;
gram = sub;
}
}
cout << gram << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int f[26][26];
int main() {
cin >> n;
cin >> s;
for (int i = 0; i < s.size() - 1; i++) {
f[s[i] - 'A'][s[i + 1] - 'A']++;
}
int maj = 0, mai = 0, ma = 0;
for (int i = 0; i < 26; i++) {
for (int j = 0; j < 26; j++) {
if (f[i][j] > ma) {
ma = f[i][j];
maj = j;
mai = i;
}
}
}
cout << (char)(mai + 'A') << (char)(maj + 'A');
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n;
string A;
cin >> n >> A;
map<string, long long int> M;
for (int i = 0; i < n - 1; i++) {
string S = "";
S += A[i];
S += A[i + 1];
M[S]++;
}
string ans = "";
long long int m = INT_MIN;
for (auto it : M) {
if (it.second > m) {
m = it.second;
ans = it.first;
}
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
int t = 1;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int t;
cin >> t;
cin >> s;
int sum = 0, f, n = 0;
for (int i = 0; i < s.length() - 2; i++) {
f = 0;
string s1 = "";
s1 = s1 + s[i] + s[i + 1];
for (int j = i + 1; j < s.length() - 1; j++) {
string s2 = "";
s2 = s2 + s[j] + s[j + 1];
if (s1 == s2) {
f++;
}
}
if (sum < f) {
sum = f;
n = i;
}
}
cout << s[n] << s[n + 1];
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = (long long)1e6 + 1;
const int inf = (long long)1e9 + 1;
long long n, mx;
string s, mxs;
map<string, long long> mp;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> s;
for (long long i = 0; i < s.size() - 1; i++) {
string t;
t += s[i];
t += s[i + 1];
mp[t]++;
if (mp[t] > mx) {
mx = mp[t];
mxs = t;
}
}
cout << mxs;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int main() {
int i, n, a, mx = INT_MIN;
string s, p, x;
cin >> n >> s;
for (i = 0; i < n - 1; i++) {
p.clear();
p += s[i];
p += s[i + 1];
mp[p]++;
if (mp[p] > mx) {
mx = mp[p];
x = p;
}
}
cout << x << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
map<string, long long> mp;
string str, res;
int main() {
long long tst, a, b, m, n, ans = 0;
scanf("%lld", &n);
cin >> str;
for (long long i = 0; i < n - 1; i++) {
string s;
s.push_back(str[i]);
s.push_back(str[i + 1]);
mp[s]++;
if (mp[s] > ans) {
ans = mp[s];
res = s;
}
}
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAX = 1e5 + 5;
const double PI = acos(-1.0);
const long double EPS = 1e-10;
const int64_t INF = 1e18 + 10;
template <typename t>
t lcm(t a, t b) {
return (a * b) / __gcd(a, b);
}
template <typename t>
t gcd(t a, t b) {
return __gcd(a, b);
}
template <typename t>
t mul_mod(t a, t b, t m) {
t res = ((a % m) * (b % m) % m);
return res;
}
template <typename t>
t add_mod(t a, t b, t m) {
t res = ((a % m) + (b % m)) % m;
return res;
}
template <typename t>
t pow_mod(t a, t b, t m) {
t res = 1;
while (b) {
if (b & 1) res = mul_mod(res, a, m);
a = mul_mod(a, a, m), b >>= 1;
}
return res % m;
}
template <typename t>
vector<t> num_vec(t num) {
t res;
while (num) res.push_back(num % 10), num /= 10;
return res;
}
template <typename t>
t vec_num(t vec) {
t res = 0;
long long mul = 1;
for (long long i = 0; i < (int)vec.size(); i++) res = vec[i] * mul, mul *= 10;
return res;
}
int countStrings(string s, string p) {
int cnt = 0;
for (long long i = 0; i < (int)s.size() - (int)p.size() + 1; i++) {
int j;
for (j = 0; j < (int)p.size(); j++)
if (s[i + j] != p[j]) break;
if (j == (int)p.size()) cnt++, j = 0;
}
return cnt;
}
int32_t main(int argc, char** argv) {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
auto tstart = clock();
int n;
cin >> n;
string s;
cin >> s;
map<string, int> cnt;
for (long long i = 0; i < 26; i++) {
string st = string(1, (char)(i + 'A'));
for (long long j = 0; j < 26; j++) {
st += (char)(j + 'A');
cnt[st] = countStrings(s, st);
st = string(1, (char)(i + 'A'));
}
}
int mx = -1;
string ans = "";
for (auto i : cnt)
if (i.second > mx) ans = i.first, mx = i.second;
cout << ans << endl;
cerr << setprecision(2) << fixed
<< "Time elapsed: " << (double)(clock() - tstart) / CLOCKS_PER_SEC
<< endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cout << setprecision(10) << fixed;
map<string, int> cnt;
int n;
cin >> n;
string str;
cin >> str;
int mx = 0;
string ans = "";
for (int i = 0; i + 1 < (int)str.size(); ++i) {
string tmp = str.substr(i, 2);
cnt[tmp]++;
if (cnt[tmp] > mx) {
ans = tmp;
mx = cnt[tmp];
}
}
cout << ans << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
bool compare(pair<string, int> a, pair<string, int> b) {
return a.first > b.first;
}
int main() {
int n;
string s;
cin >> n >> s;
map<string, int> m;
int l = s.length();
for (int i = 0; i < l - 1; i++) {
stringstream ss;
ss << s[i] << s[i + 1];
string t = ss.str();
if (m.find(t) != m.end())
m[t]++;
else
m.insert(make_pair(t, 1));
}
int max1 = -1;
string ans = "";
for (pair<string, int> p : m) {
if (p.second > max1) {
max1 = p.second;
ans = p.first;
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, mmax = 0;
string s, ans;
map<string, int> cnt;
int main() {
cin >> n >> s;
for (int i = 0; i < n - 1; i++) {
string t = s.substr(i, 2);
cnt[t]++;
}
for (map<string, int>::iterator it = cnt.begin(); it != cnt.end(); it++) {
if (it->second > mmax) {
mmax = it->second;
ans = it->first;
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, mx = 0;
string s, ans = "";
cin >> n;
cin >> s;
for (int i = 0; i < n - 1; i++) {
string res = "";
int c = 0;
res = s[i];
res += s[i + 1];
for (int j = 0; j < n; j++) {
if (res[0] == s[j] && res[1] == s[j + 1]) c++;
}
if (c > mx) {
mx = c;
ans = res;
}
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
string a;
cin >> n >> a;
string tp1, tp2, ans;
int mx = 0;
int tn = 0;
for (int i = 0; i < n - 2; i++) {
tp1.clear();
tn = 0;
tp1.push_back(a[i]);
tp1.push_back(a[i + 1]);
for (int j = 0; j < n - 1; j++) {
if (a[j] == tp1[0] && a[j + 1] == tp1[1]) {
tn++;
}
}
if (tn > mx) {
mx = tn;
ans = tp1;
}
}
if (n == 2) {
ans = a;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
const double pi = 3.141592653589793238463;
using namespace std;
void solve() {
long long n, ans = 0, index = 0;
cin >> n;
string s;
cin >> s;
map<pair<char, char>, long long> m;
for (long long i = 0; i < n - 1; i++) {
m[make_pair(s[i], s[i + 1])]++;
}
for (long long i = 0; i < n - 1; i++) {
if (m[make_pair(s[i], s[i + 1])] > ans) {
index = i;
ans = m[make_pair(s[i], s[i + 1])];
}
}
cout << s[index] << s[index + 1];
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
;
int t = 1;
while (t--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long powr(int x, int y) {
if (y == 0) return 1;
if (y % 2 == 0) {
long long temp = pow(x, y / 2);
return (temp * temp);
}
return x * pow(x, y - 1);
}
long long n;
string s;
map<string, long long> res;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> s;
for (long long i = 0; i < s.size(); i++) {
if (i + 1 < s.size()) {
string temp = "";
temp += s[i];
temp += s[i + 1];
res[temp]++;
}
}
long long mx = -1000000000000000;
string s2;
for (std::map<string, long long>::iterator it = res.begin(); it != res.end();
it++) {
if (it->second > mx) {
s2 = it->first;
mx = it->second;
}
}
cout << s2;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
string str;
cin >> n;
cin >> str;
map<string, int> freq;
for (int i = 0; i < (int)str.size() - 1; ++i) {
string temp;
temp.push_back(str[i]);
temp.push_back(str[i + 1]);
if (freq.find(temp) != freq.end())
++freq[temp];
else
freq.insert(pair<string, int>(temp, 1));
}
map<string, int>::iterator idx = freq.begin();
for (map<string, int>::iterator it = freq.begin(); it != freq.end(); ++it)
if (it->second > idx->second) idx = it;
cout << idx->first << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s;
string ans;
int cnt = 0, n;
cin >> n;
cin >> s;
int ln = s.size();
for (int i = 0; i < ln - 1; i++) {
char t[2];
t[0] = s[i];
t[1] = s[i + 1];
string tmp(t);
mp[tmp]++;
if (cnt < mp[tmp]) {
cnt = mp[tmp];
ans = tmp;
}
}
cout << ans[0] << ans[1] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
char s[111];
void input();
void solve();
int main() {
input();
solve();
}
void input() { cin >> n >> s; }
void solve() {
char ans[2];
int mnum = 0;
for (int i = 0; i < n - 1; i++) {
int num = 0;
for (int j = 0; j < n - 1; j++) {
if (s[i] == s[j] && s[i + 1] == s[j + 1]) {
num++;
}
}
if (mnum <= num) {
mnum = num;
ans[0] = s[i];
ans[1] = s[i + 1];
}
}
cout << ans[0] << ans[1];
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
std::string s;
cin >> s;
map<string, int> m;
for (int i = 0; i < n - 1; i++) {
std::string t;
t += s[i];
t += s[i + 1];
m[t]++;
}
std::string ans;
int mx = 0;
for (auto it : m) {
if (it.second > mx) {
mx = it.second;
ans = it.first;
}
}
cout << ans;
}
|
#include <bits/stdc++.h>
int main() {
int n;
std::string s;
std::cin >> n >> s;
std::unordered_map<std::string, int> m;
for (int i = 0; i <= n - 2; i++) {
std::string temp = s.substr(i, 2);
if (m.count(temp) != 0) {
m[temp]++;
} else {
m[temp] = 1;
}
}
int count = INT_MIN;
std::string ans = "";
for (auto e : m) {
if (e.second > count) {
count = e.second;
ans = e.first;
}
}
std::cout << ans << std::endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int cn = 1000000000;
bool isPrime(int n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0) return false;
return true;
}
void solve() {
long long int i, j, m, n, k;
cin >> n;
string s;
cin >> s;
map<string, long long int> st;
long long int ans = 0;
string sa, temp;
for (i = 1; i < n; i++) {
temp = s[i - 1];
temp += s[i];
st[temp]++;
if (st[temp] > ans) {
ans = st[temp];
sa = temp;
}
}
cout << sa << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long int i, j, l, t;
t = 1;
while (t--) solve();
}
|
#include <bits/stdc++.h>
using namespace std;
template <template <typename> class Array, typename T>
void outArray(Array<T>& a) {
auto it = a.begin();
for (; it != a.end(); it++) {
cout << (*it) << " ";
}
cout << "\n";
}
template <typename T>
void outVector(vector<T>& a) {
for (int i = 0; i < a.size(); i++) {
cout << a[i] << " ";
}
cout << "\n";
}
int main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
string s;
cin >> s;
string ans = "";
int maxCount = 0;
for (int i = 1; i < n; i++) {
int count = 0;
string temp = "";
temp.push_back(s[i - 1]);
temp.push_back(s[i]);
for (int j = 1; j < n; j++) {
string cmp = "";
cmp.push_back(s[j - 1]);
cmp.push_back(s[j]);
if (temp == cmp) {
count++;
}
}
if (count > maxCount) {
maxCount = count;
ans = temp;
}
}
cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
string a;
cin >> a;
unordered_map<string, int> m;
for (int i = 0; i < n - 1; i++) {
string d;
d += a[i];
d += a[i + 1];
if (m.find(d) == m.end())
m[d] = 1;
else
m[d]++;
}
int ans = 0;
string s;
for (auto node : m) {
if (node.second > ans) {
ans = node.second;
s = node.first;
}
}
for (int i = 0; i < s.size(); i++) cout << s[i];
cout << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, ans = 0;
cin >> n;
string s, x = "";
cin >> s;
map<string, long long int> m;
for (long long int i = 0; i < n - 1; i++) {
m[s.substr(i, 2)]++;
}
for (auto i : m) {
ans = max(ans, i.second);
if (ans == i.second) x = i.first;
}
cout << x << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
map<string, int> m;
for (int i = 0; i < s.size() - 1; i++) {
m[s.substr(i, 2)]++;
}
int mx = 0;
for (auto x : m) {
mx = max(mx, x.second);
}
for (auto y : m) {
if (y.second == mx) {
cout << y.first;
break;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
while (cin >> n >> s) {
int m = 0;
string result;
for (int i = 0; i < n - 1; i++) {
string sub(s, i, 2);
int cnt = 0;
for (int j = 0; j < n - 1; j++) {
if (s[j] == sub[0] && s[j + 1] == sub[1]) cnt += 1;
}
if (cnt > m) {
m = cnt;
result = sub;
}
}
cout << result << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string s;
map<string, int> mp;
int n;
void FileInit() {
{
freopen(
""
".inp",
"r", stdin);
freopen(
""
".out",
"w", stdout);
};
}
void FileDebug() {
{
freopen(
""
".inp",
"r", stdin);
freopen(
""
".out",
"w", stdout);
freopen(
""
".err",
"w", stderr);
};
}
void FileClose() {
fclose(stdin);
fclose(stdout);
}
int main() {
cin >> n >> s;
for (int i = 0; i < n - 1; ++i) {
string t;
t += s[i];
t += s[i + 1];
mp[t]++;
}
int res1 = -2345678;
string RES;
for (auto x : mp) {
if (res1 < x.second) res1 = x.second, RES = x.first;
}
cout << RES;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, maxx;
string s, max_two_gram;
unordered_map<string, int> two_gram;
int main() {
cin >> n >> s;
for (int i = 0; i < n - 1; i++) {
two_gram[s.substr(i, 2)]++;
}
for (auto i : two_gram) {
if (i.second > maxx) {
maxx = i.second;
max_two_gram = i.first;
}
}
cout << max_two_gram;
return 0;
}
|
#include <bits/stdc++.h>
const int Max = 2e5 + 100;
using namespace std;
char str[Max];
int vis[Max];
int main() {
int n;
cin >> n >> str;
for (int a = 0; a < n - 1; a++) {
int tmp = (str[a] - 'A') * 26 + str[a + 1] - 'A';
vis[tmp]++;
}
int maxs = 0, id = 0;
for (int a = 0; a < Max; a++) {
if (vis[a] > maxs) maxs = vis[a], id = a;
}
char ans[3];
ans[1] = (char)(id % 26 + 'A');
ans[2] = 0;
ans[0] = char(id / 26 + 'A');
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
char s[105];
int cnt[105];
int main() {
int n;
while (cin >> n) {
memset(cnt, 0, sizeof(cnt));
for (int i = 0; i < n; ++i) cin >> s[i];
for (int i = 0; i < n - 1; ++i) {
for (int j = 0; j < n - 1; ++j)
if (s[i] == s[j] && s[i + 1] == s[j + 1]) ++cnt[i];
}
int max = -1;
string ans;
for (int i = 0; i < n; ++i) {
if (cnt[i] > max) {
max = cnt[i];
ans = "";
ans += s[i];
ans += s[i + 1];
}
}
cout << ans << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m = 0, k, j, i;
cin >> n;
string s, s1, s2;
cin >> s;
char c;
map<string, int> m1;
for (i = 0; i < n - 1; i++) {
s1.push_back(s[i]);
s1.push_back(s[i + 1]);
m1[s1]++;
if (m < m1[s1]) {
m = max(m, m1[s1]);
s2 = s1;
}
s1.clear();
}
cout << s2;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string str, ans;
cin >> str;
int count = 0;
int max_count = 0;
for (int i = 0; i < n - 1; i++) {
count = 0;
for (int j = 0; j < n - 1; j++) {
if (str[i] == str[j] && str[i + 1] == str[j + 1]) count++;
}
if (count > max_count) {
max_count = count;
ans = str[i];
ans += str[i + 1];
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
template <typename T, typename U>
inline void amin(T &x, U y) {
if (y < x) x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y) {
if (x < y) x = y;
}
template <typename T>
inline void write(std::vector<T> list) {
std::stringstream S;
for (const T &t : list) {
S << t;
S << " ";
}
std::cout << S.str();
}
template <typename T>
inline void read(int n, std::vector<T> &list) {
std::string input;
std::getline(std::cin, input);
std::stringstream stream(input);
T temp;
while (n > 0) {
stream >> temp;
if (!stream) break;
list.push_back(temp);
--n;
}
}
int main() {
std::vector<std::string> twograms;
string test, res, S;
long long int max = 0;
cin >> max;
max = 0;
cin >> test;
for (int i = 0; i < test.size() - 1; ++i) {
S = test.substr(i, 2);
if (std::find(twograms.begin(), twograms.end(), S) == twograms.end()) {
twograms.push_back(S);
long long int count = 0;
size_t nPos = test.find(S, 0);
while (nPos != string::npos) {
count++;
nPos = test.find(S, nPos + 1);
}
if (count > max) {
max = count;
res = S;
}
}
}
cout << res;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n;
cin >> n;
string s;
cin >> s;
unordered_map<string, int> umap;
int _max = INT_MIN;
string ms;
for (int i = 0; i <= n - 2; i++) {
if (++umap[s.substr(i, 2)] > _max) {
_max = umap[s.substr(i, 2)];
ms = s.substr(i, 2);
}
}
cout << ms << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int cnt(string ss, string s) {
int ans = 0;
int n = s.size();
for (int i = 0; i < n - 1; i++) {
if (ss == s.substr(i, 2)) {
ans++;
}
}
return ans;
}
int main() {
int n;
cin >> n;
string s;
cin >> s;
string smx = "";
int mx = 0;
for (int i = 0; i < n - 1; i++) {
string ss = s.substr(i, 2);
int ans = cnt(ss, s);
if (ans > mx) {
mx = ans;
smx = ss;
}
}
cout << smx;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, string>;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
string s;
cin >> s;
map<string, int> mp;
for (int i = 0; i < (n - 1); ++i) mp[s.substr(i, 2)]++;
P ans;
for (auto &[t, x] : mp) ans = max(ans, {x, t});
cout << ans.second << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
vector<vector<int> > fre(26, vector<int>(26, 0));
cin >> s;
for (int i = 0; i < s.length() - 1; ++i) {
fre[(int)(s[i] - 'A')][(int)(s[i + 1] - 'A')]++;
}
int max_i = 0, max_j = 0;
for (int i = 0; i < 26; ++i) {
for (int j = 0; j < 26; ++j) {
if (fre[i][j] > fre[max_i][max_j]) {
max_i = i;
max_j = j;
}
}
}
char ch1 = 'A' + max_i;
char ch2 = 'A' + max_j;
cout << ch1 << ch2;
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.