text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; int main() { int a = 0, b = 0, c = 0, n, ck = 0; string arr, brr; char aa, bb; cin >> n; cin >> arr; for (int i = 0; i < n; i++) { aa = arr[i]; bb = arr[i + 1]; ck = 0; for (int j = 0; j < n; j++) { if (arr[j] == aa && arr[j + 1] == bb) { ck++; } } if (c < ck) { brr = aa; brr += bb; c = ck; } } cout << brr << endl; }
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1e9 + 7; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n; cin >> n; string s; cin >> s; map<string, long long int> m; for (long long int i = 0; i + 1 < n; i++) { string t = ""; t += s[i]; t += s[i + 1]; m[t]++; } long long int mx = 0; for (auto x : m) { mx = max(mx, x.second); } for (auto x : m) { if (x.second == mx) { cout << x.first << "\n"; return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; bool cmp(const pair<string, int> &a, const pair<string, int> &b) { return (a.second < b.second); } int main() { int n; cin >> n; string s; cin >> s; string ans; int ct = 0; unordered_map<string, int> ump; for (int i = 1; i < n; i++) { string temp = s.substr(i - 1, 2); ump[temp]++; } auto x = *max_element(ump.begin(), ump.end(), cmp); cout << x.first << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; string s; int call(string sub) { int c = 0, maxi = 0; for (int i = 0; i < s.size() - 1; i++) { if (s[i] == sub[0] && s[i + 1] == sub[1]) c++; } return c; } int main() { int n, maxi = 0; string gram; cin >> n; cin >> s; for (int i = 0; i < s.length() - 1; i++) { string sub = s.substr(i, 2); int temp = call(sub); if (temp > maxi) { maxi = temp; gram = sub; } } cout << gram << endl; }
#include <bits/stdc++.h> using namespace std; long long MOD = 1000000007; vector<int> adj[1005]; bool check(long long n) { for (long long i = 2; i * i <= n; i++) { if ((n % i) == 0) return false; } return true; } long long get(long long n) { for (int i = 2; i <= n; i++) if (n % i == 0) return i; } void solve() { int n; cin >> n; string s; cin >> s; unordered_map<string, int> m; for (int i = 0; i < s.length(); i++) { m[s.substr(i, 2)]++; } string ans; int mx = 0; for (auto x : m) { string str = x.first; if (str.length() == 2) { int check = (int)str[0] - (int)str[1]; if (x.second > mx) { ans = x.first; mx = max(mx, x.second); } } } cout << ans << endl; } 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 n; string s; int cal(int idx) { char now[2] = {s[idx], s[idx + 1]}; int count = 0; for (int i = idx; i < n - 1; i++) { if ((s[i] == now[0]) && (s[i + 1] == now[1])) { count++; } } return count; } int main() { scanf("%d", &n); cin >> s; int max = 0; int ans; for (int i = 0; i < n - 1; i++) { int count = cal(i); if (max < count) { max = count; ans = i; } } for (int i = 0; i < 2; i++) { printf("%c", s[ans + i]); } }
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, k, t, p = 0, q = 0, l = 0, r, n; cin >> n; string s, s1, s2; cin >> s; map<string, int> m; if (n == 2) { cout << s; } else if (n == 3) { cout << s[0] << s[1]; } else if (n != 2 || n != 3) { for (i = 0; i < n; i++) { m[s.substr(i, 2)]++; } map<string, int>::iterator it = m.begin(); for (it = m.begin(); it != m.end(); it++) { if (it->second > p) { p = it->second; s2 = it->first; } } cout << s2; } return 0; }
#include <bits/stdc++.h> using namespace std; bool ans(int a, int b, int &count) { if (a > b) { return false; } else if (a == b) { return true; } else { if (ans(a * 2, b, count)) { count++; return true; } if (ans(a * 3, b, count)) { count++; return true; } return false; } } int main() { map<string, int> mp; int n; cin >> n; string s; cin >> s; for (int i = 0; i < s.size() - 1; i++) { string temp; temp += s[i]; temp += s[i + 1]; if (mp.find(temp) != mp.end()) { mp[temp]++; } else { mp.insert({temp, 1}); } } string ans; int maxi = 0; for (auto i = mp.begin(); i != mp.end(); i++) { if (i->second > maxi) { maxi = i->second; ans = i->first; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; string s; map<string, int> m; int main() { int n, maxnum = 0; string ed; cin >> n >> s; for (int i = 0; i < n - 1; i++) { string ss; ss.push_back(s[i]); ss.push_back(s[i + 1]); m[ss]++; if (m[ss] > maxnum) { maxnum = m[ss]; ed = ss; } } cout << ed << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { static char cc[100]; static int kk[676]; int n, i, max, amax; scanf("%d", &n); scanf("%s", cc); max = 0; amax = 0; for (i = 1; i < n; i++) { int a = (cc[i - 1] - 'A') * 26 + (cc[i] - 'A'); if (max < ++kk[a]) { max = kk[a]; amax = a; } } printf("%c%c\n", amax / 26 + 'A', amax % 26 + 'A'); 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; s[i] != '\0'; i++) { cnt = 01; for (j = 0; s[j] != '\0'; 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> #pragma GCC optimize("O3") using namespace std; int main() { map<string, int> CNT; string s; int n; cin >> n; cin >> s; for (int i = 0; i < s.size() - 1; ++i) { CNT[s.substr(i, 2)]++; } string ans = s.substr(0, 2); for (auto i : CNT) { if (i.second > CNT[ans]) ans = i.first; } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; string s; cin >> s; vector<string> v; int mm = 0, max = 0; for (int i = 0; i < n - 1; i++) v.push_back(s.substr(i, 2)); sort(v.begin(), v.end()); string s1 = v[0]; for (int i = 0; i < n - 1; i++) { if (v[i] == v[i + 1]) mm++; else { if (mm > max) { max = mm; s1 = v[i - 1]; } mm = 0; } } cout << s1 << "\n"; ; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t = 1; while (t--) { int n, mx = 0; string s, a; cin >> n >> s; map<string, int> m; for (int i = 0; i < n - 1; i++) { a = s.substr(i, 2); m[a]++; } for (auto it = m.begin(); it != m.end(); it++) { if (it->second >= mx) { mx = it->second; a = it->first; } } cout << a << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int n; string s; void test_case() { cin >> n; cin.ignore(110, '\n'); cin >> s; string ans; int mx_cnt = -1; for (int i = 0; i < n - 1; ++i) { string sub = s.substr(i, 2); int cnt = 0; for (int j = 0; j < n - 1; ++j) { if (sub[0] == s[j] && sub[1] == s[j + 1]) { ++cnt; } } if (cnt > mx_cnt) { mx_cnt = cnt; ans = sub; } } cout << ans << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); test_case(); return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") using namespace std; long long MOD = 998244353; double eps = 1e-12; void solve() { int n; cin >> n; string s; cin >> s; pair<char, int> p, p1; map<pair<char, char>, int> maap; int mx = 0; for (int i = 0; i < n - 1; i++) { p1 = make_pair(s[i], s[i + 1]); maap[p1]++; if (maap[p1] > mx) { mx = maap[p1]; p = p1; } } cout << p.first << (char)p.second << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t = 1; for (int it = 1; it <= t; it++) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); std::ios::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; map<string, int> m; int i = 0; while (true) { string ss = s.substr(i, 2); m[ss]++; i++; if (i + 2 > s.size()) { break; } } map<string, int>::iterator iter; int sol = -1; string sss; for (iter = m.begin(); iter != m.end(); iter++) { if (sol < iter->second) { sol = iter->second; sss.clear(); sss.append(iter->first); } } cout << sss << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { map<string, int> grams; int n; cin >> n; string a; string temp; cin >> a; for (int i = 0; i < n - 1; i++) { temp = a[i]; temp += a[i + 1]; grams[temp]++; } int p = 0; for (map<string, int>::iterator i = grams.begin(); i != grams.end(); ++i) { if (i->second > p) { p = i->second; temp = i->first; } } cout << temp << endl; return 0; }
#include <bits/stdc++.h> using namespace std; string pan; char read[1001], s1[1001], s2[10001]; int i, j, k, n, m = -1, ans[1001]; int main() { cin >> n; for (i = 1; i <= n; ++i) { cin >> read[i]; } for (i = 1; i < n; ++i) { s1[i] = read[i]; s2[i] = read[i + 1]; for (j = 1; j < n; ++j) { if (s1[i] == read[j] && s2[i] == read[j + 1]) ++ans[i]; continue; } } for (i = 1; i < n; ++i) { if (ans[i] > m) m = ans[i], k = i; } cout << s1[k]; cout << s2[k]; }
#include <bits/stdc++.h> using namespace std; void test_case() {} bool found(string t, vector<string> s) { bool f = false; for (int i = 0; i < (int)s.size(); ++i) { if (s[i] == t) { f = true; break; } } return f; } int main() { int n; cin >> n; string p; cin >> p; vector<string> s; vector<string> a; for (int i = 0; i < n - 1; i++) { string t = ""; for (int j = i; j < i + 2; ++j) { t += p[j]; } a.push_back(t); if (!found(t, s)) { s.push_back(t); } } int maxm = 0; string ans = "?"; for (string x : s) { int cnt = 0; for (int j = 0; j < n; ++j) { if (a[j] == x) { ++cnt; } } if (cnt > maxm) { maxm = cnt; ans = x; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int solve(string t, string s) { int ans = 0; for (int i = 0; i < s.length() - 1; i++) { string temp = ""; temp = temp + s[i]; temp = temp + s[i + 1]; if (temp == t) ans++; } return ans; } int main() { std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); int n; string s; cin >> n >> s; int ans = 0; string an; for (int i = 0; i < s.length() - 1; i++) { string t = ""; t = t + s[i]; t = t + s[i + 1]; int sl = solve(t, s); if (ans < sl) { an = t; ans = sl; } } cout << an; return 0; }
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; long long n, m, i, j, frq[30][30]; string s; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); if (0) ; cin >> n >> s; for (i = 0; i < n - 1; i++) { frq[s[i] - 'A'][s[i + 1] - 'A']++; } string ans = ""; long long mxfrq = 0; for (i = 0; i < 30; i++) { for (j = 0; j < 30; j++) { if (frq[i][j] > mxfrq) { ans = ""; ans += (char)('A' + i); ans += (char)('A' + j); mxfrq = frq[i][j]; } } } cout << ans << endl; }
#include <bits/stdc++.h> int solve() { int n; scanf("%d", &n); char s[128] = {}; scanf("%s", s); int ans = 0; char ans_a = 0, ans_b = 0; for (int i = 0; i < n - 1; ++i) { char a = s[i]; char b = s[i + 1]; int cur = 0; for (int j = 0; j < n - 1; ++j) { if (a == s[j] && b == s[j + 1]) ++cur; } if (cur > ans) { ans = cur; ans_a = a; ans_b = b; } } printf("%c%c\n", ans_a, ans_b); return 0; } int main(int argc, char* argv[]) { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; string st, s; int n, a[205][205], maxz; int main() { cin >> n >> st; for (int i = 1; i < st.size(); i++) { a[st[i - 1]][st[i]]++; if (a[st[i - 1]][st[i]] > maxz) { maxz = a[st[i - 1]][st[i]]; s = ""; s = s + st[i - 1] + st[i]; } } cout << s; return 0; }
#include <bits/stdc++.h> using namespace std; int const M = 2e5 + 10, M2 = 1e6 + 10, mod = 1e9 + 7, inf = 1e9 + 10; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, max = 0; cin >> n; string s, t, z; cin >> s; for (long long i = 0; i < n - 1; i++) { t = s[i]; t += s[i + 1]; long long cnt = 0; for (long long m = i; m < n - 1; m++) { if (s[m] == t[0] && s[m + 1] == t[1]) { cnt++; } } if (cnt > max) { max = cnt; z = t; cnt = 0; } t.erase(0, 2); } cout << z; return 0; }
#include <bits/stdc++.h> using namespace std; char ch[105]; string s[105]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> ch[i]; } for (int i = 1; i < n; i++) { s[i - 1] = s[i - 1] + ch[i - 1] + ch[i]; } int mx = 0; string res = ""; for (int i = 0; i < n - 1; i++) { int t = 0; for (int j = 0; j < n; j++) { if (i != j) { if (s[i] == s[j]) { t++; } } } if (mx <= t) { mx = t; res = s[i]; } } cout << res; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string str; cin >> str; map<string, int> mp; for (int i = 1; i < n; i++) { string tt = ""; tt += str[i - 1]; tt += str[i]; mp[tt]++; } int cnt = -1; string ans; for (auto x : mp) { if (cnt < x.second) { cnt = x.second; ans = x.first; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k, ans, maxx = 000; string s, s1, s2, s3; cin >> n; cin >> s; for (int i = 0; i < s.size(); ++i) { s1 = s[i]; s1 += s[i + 1]; for (int j = 0; j < s.size(); ++j) { s2 = s[j]; s2 += s[j + 1]; if (s1 == s2) { ans++; } } if (maxx < ans) { maxx = ans; s3 = s1; } ans = 0; } cout << s3 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, mx = -1; cin >> n; string s, sb = ""; cin >> s; map<string, long long int> mp; for (long long int i = 0; i < n - 1; i++) { string sa = ""; for (long long int j = 0; j < 2; j++) { sa += s[i + j]; } mp[sa]++; } for (auto it = mp.begin(); it != mp.end(); it++) { if (mx < it->second) { mx = it->second; sb = it->first; } } cout << sb; }
#include <bits/stdc++.h> using namespace std; int main() { map<string, int> mp; map<string, int>::iterator it; int n; cin >> n; string arr; cin >> arr; for (int i = 0; i < n - 1; i++) mp[arr.substr(i, 2)]++; int sum = 0; string ss; for (it = mp.begin(); it != mp.end(); it++) if (it->second > sum) { sum = it->second; ss = it->first; } cout << ss << endl; return 0; }
#include <bits/stdc++.h> using namespace std; char a[105]; int f[50000]; int main() { int n; scanf("%d", &n); scanf("%s", a); memset(f, 0, sizeof(f)); int ma = 0; char f1, f2; for (int i = 1; i < strlen(a); i++) { f[(a[i - 1] - 50) * 100 + a[i] - 50]++; if (f[(a[i - 1] - 50) * 100 + a[i] - 50] > ma) { ma = f[(a[i - 1] - 50) * 100 + a[i] - 50]; f1 = a[i - 1]; f2 = a[i]; } } printf("%c%c\n", f1, f2); }
#include <bits/stdc++.h> using namespace std; map<string, int> mm; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; string s; cin >> n >> s; int ans = 0; if (n == 1) return cout << ans, 0; for (int i = 0; i < n - 1; i++) { string t = ""; t = t + s[i] + s[i + 1]; mm.insert(make_pair(t, 1)); for (int j = i + 1; j < n - 1; j++) { string temp = ""; temp = temp + s[j] + s[j + 1]; if (t == temp) { mm[t]++; } } } string res; for (auto it = mm.begin(); it != mm.end(); it++) { if (it->second > ans) { ans = it->second; res = it->first; } } cout << res; return 0; }
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); map<string, long long> mp; long long n; cin >> n; string s; cin >> s; for (long long i = 0; i < n - 1; i++) { mp[s.substr(i, 2)]++; } long long mx = 0; for (auto p : mp) mx = max(mx, p.second); for (auto p : mp) { if (mx == p.second) { cout << p.first; return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a, hit = 0; string str, ans; cin >> a; cin >> str; for (int i = 1; i < a; i++) { int hii = 0; string b; b = b + str[i - 1] + str[i]; for (int j = i + 1; j < a; j++) { string c; c = c + str[j - 1] + str[j]; if (c == b) hii++; } if (hit <= hii) { ans = b; hit = hii; } } cout << ans; }
#include <bits/stdc++.h> using namespace std; string n, m; int a, res, sum; char h, k, hres, kres; int main() { cin >> a; cin >> n; res = 0; for (int i = 0; i <= a - 2; i++) { h = n[i]; k = n[i + 1]; sum = 0; for (int j = 0; j <= a - 2; j++) { if (((h == n[j]) && (k == n[j + 1]))) sum++; } if (sum > res) { res = sum; hres = h; kres = k; } } cout << hres << kres; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; string s; cin >> s; unordered_map<string, int> a; for (int i = 0; i < s.length() - 1; i++) { string k = s.substr(i, 2); if (a.find(k) == a.end()) a.insert(make_pair(k, 1)); else a[k]++; } int maxx = -1; string p = ""; unordered_map<string, int>::iterator it; for (it = a.begin(); it != a.end(); it++) { if (it->second > maxx) { maxx = it->second; p = it->first; } } cout << p; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; string s; cin >> s; map<string, int> m; for (int i = 0; i < n; i++) { if (i + 1 < n) { string s1 = ""; s1 += s[i]; s1 += s[i + 1]; m[s1]++; } } auto it = m.begin(); string ans = ""; int c = 0; while (it != m.end()) { int cnt = it->second; if (cnt > c) { c = cnt; ans = it->first; } it++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; void debugv(std::vector<long long> v); void printv(std::vector<long long> v); void inputv(std::vector<long long> &v); void solve() { long long n; cin >> n; string s; cin >> s; unordered_map<string, long long> mp; for (long long i = 0; i < n - 1; i++) { string k = s.substr(i, 2); mp[k]++; } long long maxi = INT_MIN; string ans = ""; for (auto i : mp) { if (i.second > maxi) { ans = i.first; maxi = i.second; } } cout << ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; t = 1; while (t--) { solve(); cout << "\n"; } return 0; } void debugv(std::vector<long long> v) { long long size = v.size(); for (long long i = 0; i < size; i++) { cerr << v[i] << " "; } cout << '\n'; } void printv(std::vector<long long> v) { long long size = v.size(); for (long long i = 0; i < size; i++) { cout << v[i] << " "; } cout << '\n'; } void inputv(std::vector<long long> &v) { for (auto &i : v) { cin >> i; } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; string s; cin >> n >> s; map<string, int> mapp; int max = 0; string ans; for (int i = 0; i < n - 1; i++) { string c = s.substr(i, 2); auto x = mapp.find(c); if (x == mapp.end()) mapp[c] = 0; else { mapp[c]++; if (max < (x->second)) { max = x->second; ans = c; } } } if (max == 0) ans = s.substr(0, 2); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; map<string, int> mp; string c, ans; int max = 0; for (int i = 0; i < n - 1; i++) { c = s[i]; c.push_back(s[i + 1]); mp[c]++; if (mp[c] > max) { max = mp[c]; ans = c; } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int res = 0; string ans; for (int i = 0; i < n - 1; ++i) { int cur = 0; for (int j = 0; j < n - 1; ++j) if (s[j] == s[i] && s[j + 1] == s[i + 1]) ++cur; if (res < cur) { res = cur; ans = string(1, s[i]) + string(1, s[i + 1]); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char a[n + 1]; scanf("%s", a); map<string, int> ans; string s = ""; for (int i = 0; i < n - 1; i++) { s.push_back(a[i]); s.push_back(a[i + 1]); ans[s]++; s = ""; } map<string, int>::iterator itr; int max = 0; string str; for (itr = ans.begin(); itr != ans.end(); itr++) { if (max < itr->second) { max = itr->second; str = itr->first; } } cout << str; }
#include <bits/stdc++.h> int main() { int n, i, j, b, count, a = 0; scanf("%d", &n); char str[n + 5]; scanf("%s", str); for (i = 0; i < n - 1; i++) { count = 0; for (j = 0; j < n - 1; j++) { if ((str[i] == str[j]) && (str[i + 1] == str[j + 1])) count++; } if (count > a) { a = count; b = i; } } printf("%c%c", str[b], str[b + 1]); return 0; }
#include <bits/stdc++.h> using namespace std; int n; string s; int cnt[26][26]; int main() { int res1 = 0, res2 = 0; cin >> n >> s; for (int i = 0; i < s.size() - 1; ++i) { int a1 = s[i] - 'A'; int a2 = s[i + 1] - 'A'; cnt[a1][a2]++; if (cnt[a1][a2] > cnt[res1][res2]) { res1 = a1; res2 = a2; } } cout << (char)(res1 + 'A') << (char)(res2 + 'A') << "\n"; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; string s; cin >> s; int m = 0; string str = "aa"; for (int i = 0; i < t - 1; i++) { int c = 0; for (int j = i; j < t - 1; j++) { if (s[j] == s[i] && s[j + 1] == s[i + 1]) { c += 1; } } if (m < c) { m = c; str[0] = s[i]; str[1] = s[i + 1]; } } cout << str; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); map<string, int> m; int n; string s; cin >> n >> s; for (size_t i = 0; i < s.size() - 1; ++i) m[s.substr(i, 2)]++; int maior = 0; for (const auto& c : m) if (c.second > maior) { maior = c.second; s = c.first; } cout << s << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; map<string, int> m; for (int i = 0; i < n - 1; i++) { string tmp = "" + string(1, s[i]) + string(1, s[i + 1]); m[tmp]++; } int mx = -100; for (auto i : m) { if (i.second > mx) { mx = i.second; } } for (auto i : m) { if (i.second == mx) { cout << i.first; return 0; } } }
#include <bits/stdc++.h> using namespace std; int main() { int n, p = 0, ans = 0; string s, dvg, answ, r_dvg; cin >> n >> s; for (int i = 0; i < n - 1; i++) { dvg = s.substr(i, 2); for (int j = i; j < n - 1; j++) { r_dvg = s.substr(j, 2); if (dvg == r_dvg) { p++; } } if (p > ans) { ans = p; answ = dvg; } p = 0; } cout << answ << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n; string s; struct poin { char ss[2]; int sum; }; poin pp[200]; int vis[200]; int main() { while (cin >> n) { for (int i = 0; i < 200; i++) { pp[i].sum = 0; } memset(vis, 0, sizeof(vis)); cin >> s; for (int i = 0; i < s.length() - 1; i++) { pp[i].ss[0] = s[i]; pp[i].ss[1] = s[i + 1]; } for (int j = 0; j < s.length() - 1; j++) { if (!vis[j]) { for (int i = 0; i < s.length() - 1; i++) { if (pp[j].ss[0] == s[i] && pp[j].ss[1] == s[i + 1]) { pp[j].sum++; vis[i] = 1; } } } } int maxn = -1; int lop = -1; for (int i = 0; i < s.length() - 1; i++) { if (maxn < pp[i].sum) { maxn = pp[i].sum; lop = i; } } cout << pp[lop].ss << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; int n; cin >> n; cin >> s; string ans = ""; int ans_rep = 0; for (int i = 0; i < n - 1; i++) { string gram2 = s.substr(i, 2); int rep = 0; for (int j = 0; j < n - 1; j++) { if (gram2 == s.substr(j, 2)) rep++; } if (rep > ans_rep) { ans = gram2; ans_rep = rep; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int testCases = 1; while (testCases--) { int n; cin >> n; char arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } char ans[2]; int max = INT_MIN; for (int i = 0; i < n - 1; i++) { int temp = 0; char brr[2]; brr[0] = arr[i]; brr[1] = arr[i + 1]; for (int j = 0; j < n; j++) { if (arr[j] == brr[0] && arr[j + 1] == brr[1]) { temp++; } } if (temp > max) { max = temp; ans[0] = brr[0]; ans[1] = brr[1]; } } cout << ans[0] << ans[1] << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int coun[27][27]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; string s; cin >> s; int len = s.size(); for (int i = 0; i < len - 1; i++) { coun[s[i] - 'A'][s[i + 1] - 'A']++; } int maxn = 0; int x, y; for (int i = 0; i <= 25; i++) { for (int j = 0; j <= 25; j++) { if (coun[i][j] > maxn) { maxn = coun[i][j]; x = i, y = j; } } } cout << (char)('A' + x) << (char)('A' + y) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; bool compare(const pair<long long, long long> &a, const pair<long long, long long> &b) { return (a.second < b.second); } vector<long long> subseg(vector<long long> v) { long long n = v.size(), i = 0; vector<long long> res(n + 1, 0); while (i < n) { if (v[i] == 0) { i++; continue; } long long j = i; while (j < n and v[j] == 1) { j++; } for (int k = 1; k <= j - i; k++) { res[k] += j - i - k + 1; } i = j; } return res; } vector<bool> PRIME(1000005, true); void sieve(long long n) { PRIME[0] = false; PRIME[1] = false; for (long long p = 2; p * p <= n; p++) { if (PRIME[p] == true) { for (long long i = p * p; i <= n; i += p) { PRIME[i] = false; } } } } long long a, b, c, d, e, m, n, p, x, y, z, mn, mx; long long arr[10000005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long t = 1; while (t--) { cin >> n; string s, str; cin >> s; map<string, long long> my; for (int i = 0; i < n - 1; i++) { str = s.substr(i, 2); my[str]++; } mx = -1; for (auto it : my) { str = it.first; if (mx < it.second) { mx = it.second; s = it.first; } } cout << s; h:; cout << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int n; void f(int x) { if (x == 0) return; if (n % 10) n -= 1, f(x - 1); else n /= 10, f(x - 1); } int main() { int tt = 1; while (tt--) { int mx = 0; vector<string> v; map<string, int> freq; cin >> n; string s; cin >> s; for (int i = 0; i + 1 < n; i++) { string g = ""; char c1 = s[i], c2 = s[i + 1]; g.push_back(c1); g.push_back(c2); freq[g]++; mx = max(freq[g], mx); } for (auto [key, value] : freq) { if (value == mx) { cout << key << endl; return 0; } } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int ln; string st; cin >> ln; cin >> st; char a, b; int fcnt = 0; for (int i = 0; i < ln; i++) { char fs = st[i]; char bs = st[i + 1]; int cnt = 0; for (int j = 0; j < ln; j++) { if (st[j] == fs && st[j + 1] == bs) { cnt++; } } if (fcnt < cnt) { a = st[i]; b = st[i + 1]; fcnt = cnt; } } cout << a << b << endl; }
#include <bits/stdc++.h> using namespace std; const int maxn = 107; char str[maxn]; int main() { int n; cin >> n; cin >> str; map<string, int> mp; int maxx = 0; string ans; for (int i = 0; i < n - 1; i++) { string s; s += str[i]; s += str[i + 1]; mp[s]++; if (mp[s] > maxx) { maxx = mp[s]; ans = s; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int M = 2e5 + 1; int inf = 1e9 + 1; int n, a[29][29], maxi, j; int main() { ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL); string s; cin >> n; cin >> s; for (int i = 0; i < n - 1; i++) { a[int(s[i]) - 65][int(s[i + 1]) - 65]++; if (maxi < a[int(s[i]) - 65][int(s[i + 1]) - 65]) maxi = a[int(s[i]) - 65][int(s[i + 1]) - 65], j = i; } cout << s[j] << s[j + 1]; }
#include <bits/stdc++.h> using namespace std; int main() { map<string, int> m; int n; cin >> n; string s; cin >> s; for (int i = 0; i != n - 1; i++) { string b; b += s[i]; b += s[i + 1]; if (m.find(b) == m.end()) { m.insert({b, 1}); } else { m.at(b)++; } } set<pair<int, string>, greater<pair<int, string>>> v; for (auto& i : m) { v.insert({i.second, i.first}); } cout << (*v.begin()).second; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int res = 0; string ans; for (int i = 0; i < n - 1; ++i) { int cur = 0; for (int j = 0; j < n - 1; ++j) if (s[j] == s[i] && s[j + 1] == s[i + 1]) ++cur; if (res < cur) { res = cur; ans = string(1, s[i]) + string(1, s[i + 1]); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, maxxx = 0; string s, test, fin; map<string, int> occ; cin >> n >> s; for (int i = 0; i < n - 1; i++) { test = ""; test += s[i]; test += s[i + 1]; occ[test]++; } for (map<string, int>::iterator x = occ.begin(); x != occ.end(); ++x) { if (x->second > maxxx) { fin = x->first; maxxx = x->second; } } cout << fin; }
#include <bits/stdc++.h> using namespace std; int main() { int n, c, 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 = 0; 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; string s; cin >> n >> s; char a, b, A, B; int maxx = 0, counter = 0; for (int i = 0; i < n - 1; i++) { a = s[i]; b = s[i + 1]; counter = 0; for (int j = 0; j < n - 1; j++) { if (a == s[j] && b == s[j + 1]) { counter++; } if (maxx < counter) { A = a; B = b; maxx = counter; } } } cout << A << B; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int size, i, j, k, l; char ch1, ch2; char res1, res2; int count = 0; int res = 0; cin >> size; string str; cin >> str; if (str.length() == 2) cout << str; else { for (i = 0, j = 1; i < str.length() && j < str.length(); i++, j++) { ch1 = str[i]; ch2 = str[j]; count = 0; for (k = 0, l = 1; k < str.length() && l < str.length(); k++, l++) { if (str[k] == ch1 && str[l] == ch2) count++; } if (count > res) { res = count; res1 = ch1; res2 = ch2; } } cout << res1 << res2; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef struct two_pair { int num; string src; } two_pair; void IsInVector(vector<two_pair> &list_pair, string pair); int main() { string s, pair; int n; two_pair max{0, ""}; vector<two_pair> num_two_gram; char car[2]; cin >> n; cin >> s; for (int i = 0; i < n - 1; i++) { pair = ""; car[0] = s[i]; car[1] = s[i + 1]; pair.push_back(car[0]); pair.push_back(car[1]); IsInVector(num_two_gram, pair); } for (two_pair p : num_two_gram) { if (p.num > max.num) { max = {p.num, p.src}; } } cout << max.src; return 0; } void IsInVector(vector<two_pair> &list_pair, string pair) { for (two_pair &p : list_pair) { if (!(pair.compare(p.src))) { p.num += 1; return; } } two_pair aux{1, pair}; list_pair.push_back(aux); return; }
#include <bits/stdc++.h> using namespace std; map<string, int> t; string s; int n; bool comp(pair<string, int> a, pair<string, int> b) { return (a.second > b.second); } int main() { map<string, int>::iterator it; cin >> n; cin >> s; string ss; for (int i = 0; i < n - 1; i++) { ss = s.substr(i, 2); t[ss]++; } pair<string, int> a = *t.begin(); for (it = t.begin(); it != t.end(); it++) { if (comp(*it, a)) a = *it; } cout << a.first; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; string s; cin >> s; map<string, long long> m; long long t = 0; string p; for (long long i = 0; i < n - 1; i++) { m[{s[i], s[i + 1]}]++; if (t < m[{s[i], s[i + 1]}]) { t = m[{s[i], s[i + 1]}]; p = {s[i], s[i + 1]}; } } cout << p; }
#include <bits/stdc++.h> using namespace std; template <typename T> void read(vector<T> &a) { for (long long int i = 0; i < (long long int)(a).size(); i++) cin >> a[i]; } template <typename T> void write(vector<T> a, long long int start = 0) { for (long long int i = start; i < (long long int)(a).size(); i++) cout << a[i] << ' '; cout << '\n'; } long long int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89}; string alpha = "abcdefghijklmnopqrstuvwxyz"; void solve() { string s, ans = ""; long long int n, mx = 0; cin >> n >> s; map<string, long long int> mp; for (long long int i = 0; i < n - 1; i++) { string ch = ""; ch += s[i], ch += s[i + 1]; if (mp[ch] == 0) mp[ch] = 1; else mp[ch]++; if (mx < mp[ch]) { mx = mp[ch]; ans = ch; } } cout << ans << '\n'; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); long long int t = 1; for (long long int i = 1; i <= t; ++i) { solve(); } }
#include <bits/stdc++.h> #pragma GCC optimize("O3") const long long INF = 0x3f3f3f3f3f3f3f3f; const long long llinf = (1LL << 61); const int inf = (1 << 30); const int nmax = 1e5 + 50; const int mod = 1e9 + 7; using namespace std; int n, i, nr, mx, j; string ans, s[105], tmp; char c[105]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cerr.tie(0); cout.tie(0); cin >> n; for (i = 1; i <= n; i++) cin >> c[i]; for (i = 1; i < n; i++) s[i] += c[i], s[i] += c[i + 1]; for (i = 1; i < n; i++) { nr = 0; for (j = 1; j < n; j++) { tmp = ""; tmp += c[j], tmp += c[j + 1]; if (tmp == s[i]) nr++; } if (nr > mx) mx = nr, ans = s[i]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; set<char> s1; set<char>::iterator it1, it2; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int a, b, i, j, k, n, m, p, q, x, y, ct1, ct2, t, w, sum; string str, str1, str2; char ch1, ch2; while (cin >> n) { s1.clear(); cin >> str; char ans[2]; for (i = 0; str[i]; i++) { s1.insert(str[i]); } int len = str.length(); int mx = 0; for (it1 = s1.begin(); it1 != s1.end(); it1++) { ch1 = *it1; for (it2 = s1.begin(); it2 != s1.end(); it2++) { ch2 = *it2; ct1 = 0, ct2 = 0; for (i = 1; i < len; i++) { if (str[i - 1] == ch1 && str[i] == ch2) ++ct1; else if (str[i - 1] == ch2 && str[i] == ch1) ++ct2; } if (mx < ct1) { ans[0] = ch1, ans[1] = ch2; mx = ct1; } else if (mx < ct2) { ans[0] = ch2, ans[1] = ch1; mx = ct2; } } } ans[2] = '\0'; cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; int a[n - 1]; for (int i = 0; i < n; i++) { a[i] = 0; } for (int i = 0; i < n - 1; i++) { string c = s.substr(i, 2); for (int j = 0; j < n - 1; j++) { if (c == s.substr(j, 2)) { a[i]++; } } } int mx = -1, ans = 0; for (int i = 0; i < n; i++) { if (mx < a[i]) { mx = a[i]; ans = i; } } cout << s.substr(ans, 2) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, count = 0, max = 0; string str, s[105], sss, ss; cin >> n >> str; size_t npos = -1; ss = str; for (long long i = 0; i < n - 1; i++) { sss.push_back(str[i]); sss.push_back(str[i + 1]); while (str.find(sss) != npos) { str.replace(str.find(sss), 1, "*"); count++; } s[count] = sss; if (count > max) max = count; str = ss; count = 0; sss.clear(); continue; } cout << s[max]; }
#include <bits/stdc++.h> using namespace std; int main() { long long n; char a[110]; cin >> n >> a; int gram[27][27] = {0}; for (int i = 0; i < 26; ++i) { for (int j = 0; j < 26; ++j) { for (int k = 1; a[k] != '\0'; k++) { if (a[k - 1] - 'A' == i && a[k] - 'A' == j) { gram[i][j]++; } } } } int big_count = 0; int i_index = 0; int j_index = 0; for (int i = 0; i < 26; ++i) { for (int j = 0; j < 26; j++) { if (gram[i][j] > big_count) { big_count = gram[i][j]; i_index = i; j_index = j; } } } cout << (char)(i_index + 'A') << (char)(j_index + 'A'); return 0; }
#include <bits/stdc++.h> using namespace std; int m[28][28]; char s[103]; int maxi, maxj; int main() { int n; scanf("%d", &n); getchar(); scanf("%c", &s[0]); for (int i = 1; i < n; i++) { scanf("%c", &s[i]); ++m[(int)s[i - 1] - (int)'A'][(int)s[i] - (int)'A']; } for (int i = 0; i < 28; i++) for (int j = 0; j < 28; j++) if (m[i][j] > m[maxi][maxj]) { maxi = i; maxj = j; } cout << (char)(maxi + (int)'A') << (char)(maxj + (int)'A'); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string output = ""; int n; cin >> n; int mx = 0; map<string, int> mp; string s; cin >> s; for (int i = 0; i < s.length() - 1; i++) { string x = ""; x += s[i]; x += s[i + 1]; mp[x]++; if (mp[x] > mx) { mx = mp[x]; output = x; } } cout << output << endl; return 0; }
#include <bits/stdc++.h> int main() { using std::cin; using std::cout; using std::endl; using std::ios_base; using std::string; using std::unordered_map; ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; string str; cin >> n; cin >> str; unordered_map<string, int> umap; for (int i = 0; i < n - 1; i++) { umap[string(1, str[i]) + str[i + 1]]++; } int max = 0; string ans; for (auto &el : umap) { if (el.second > max) { ans = el.first; max = el.second; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n; map<pair<char, char>, int> mp; pair<char, char> ans; int maxn; char str[2050]; int main() { scanf("%d", &n); scanf("%s", str + 1); pair<char, char> fin; for (int i = 1; i < n; ++i) { ans = pair<char, char>(str[i], str[i + 1]); mp[ans]++; if (mp[ans] > maxn) { maxn = mp[ans]; fin = ans; } } printf("%c%c", fin.first, fin.second); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; string ans; cin >> s; map<string, int> m; int maz = 0; for (int i = 0; i < n - 1; i++) { string t = s.substr(i, 2); m[t]++; if (m[t] > maz) { maz = m[t]; ans = t; } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int cur, goal, q, cnt; void rec(int n, int v) { if (n == q) { if (v == goal) cnt++; return; } rec(n + 1, v + 1); rec(n + 1, v - 1); } int main() { std::ios::sync_with_stdio(false); int n; string s; cin >> n; cin >> s; map<string, int> m; for (int i = 1; i < n; i++) { string tmp = s.substr(i - 1, 2); if (m[tmp]) m[tmp]++; else m[tmp] = 1; } string ans = ""; int t = 0; for (std::map<string, int>::iterator it = m.begin(); it != m.end(); it++) { if (it->second >= t) { t = it->second; ans = it->first; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int i, l, n; l = 0; string s, t; map<string, int> m; cin >> n; cin >> s; for (i = 0; i < (n - 1); i++) { t = ""; t.append(1, s[i]); t.append(1, s[i + 1]); m[t]++; } for (auto it = m.begin(); it != m.end(); it++) l = max(l, it->second); for (auto it = m.begin(); it != m.end(); it++) { if (l == it->second) { cout << it->first; break; } } return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, ans = 0; cin >> n; string s, t; cin >> s; vector<pair<long long int, long long int> > v; for (long long int i = 0; i < n - 1; i += 1) { long long int cnt = 1; t = s.substr(i, 2); for (long long int j = i + 1; j < n - 1; j += 1) { if (t == s.substr(j, 2)) cnt++; } ans = max(ans, cnt); if (cnt == ans) v.push_back(make_pair(cnt, i)); } for (long long int i = 0; i < v.size(); i += 1) { if (v[i].first == ans) { cout << s[v[i].second] << s[v[i].second + 1]; break; } } } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); long long int t; t = 1; while (t--) { solve(); cout << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t = 0, f, j, a[100] = {0}, k = 0, r, c = 0; string s, s1[100]; cin >> t >> s; for (f = 0; f < t - 1; f++) { for (c = 0; c < 2; c++) s1[f] += s[c + f]; } for (f = 0; f < t - 1; f++) for (j = t - 2; f <= j; j--) if (s1[f] == s1[j]) a[f]++; for (f = 0; f < t - 1; f++) if (k < a[f]) { k = a[f]; r = f; } cout << s1[r]; }
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); long long int n = 0; cin >> n; string s; cin >> s; map<string, long long int> answers; for (long long int i = 0; i < n - 1; ++i) ++answers[s.substr(i, 2)]; long long int max_cnt = 0; string max_ans; for (const auto &[key, val] : answers) { if (val > max_cnt) { max_cnt = val; max_ans = key; } } cout << max_ans; }
#include <bits/stdc++.h> const int N = (5e5); const long long INF = (long long)(2e9) + 7; using namespace std; int n, k, a[N], mx; string s, ans; map<string, int> M; int main() { ios_base ::sync_with_stdio(false); cin.tie(0); cin >> n >> s; for (int i = 0; i <= (int)(s.size()) - 2; ++i) { M[s.substr(i, 2)]++; } for (auto it : M) { if (it.second > mx) { mx = it.second; ans = it.first; } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int64_t n; string s; cin >> n; cin >> s; std::map<int, int> compteur; int64_t max = 0; string max_s; for (int64_t i = 0; i < n - 1; i++) { compteur[(s[i] - 'A') * 26 + (s[i + 1] - 'A')]++; if (compteur[(s[i] - 'A') * 26 + (s[i + 1] - 'A')] > max) { max++; max_s = s.substr(i, 2); } } cout << max_s; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; map<string, int> m; string cur; cur = s[0]; cur += s[1]; m[cur]++; for (int i = 2; i < n; i++) { cur.erase(cur.begin()); cur.push_back(s[i]); m[cur]++; } int f = 0; string mostf; for (auto it = m.begin(); it != m.end(); it++) { if ((*it).second > f) { f = (*it).second; mostf = (*it).first; } } cout << mostf << endl; return 0; }
#include <bits/stdc++.h> using namespace std; map<string, int> mp; map<string, int>::iterator it; int main() { int n; scanf("%d", &n); string a; cin >> a; for (int i = 0; i < n - 1; i++) { string b; b += a[i]; b += a[i + 1]; mp[b]++; } int maxx = 0; string re; for (it = mp.begin(); it != mp.end(); it++) { if (it->second > maxx) { maxx = it->second; re = it->first; } } cout << re << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int n, cnt, mx = 0; cin >> n; string a, ans; cin >> a; for (int i = 1; i < n; i++) { cnt = 0; for (int j = 1; j < n; j++) { if (a[j] == a[i] && a[j - 1] == a[i - 1]) { cnt++; } } if (cnt > mx) { mx = cnt; ans = a[i - 1]; ans += a[i]; } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int res = 0; string ans; for (int i = 0; i < n - 1; ++i) { int curr = 0; for (int j = 0; j < n - 1; ++j) if (s[j] == s[i] && s[j + 1] == s[i + 1]) ++curr; if (res < curr) { res = curr; ans = string(1, s[i]) + string(1, s[i + 1]); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char c[n]; for (int i = 0; i < n; i++) { cin >> c[i]; } set<pair<char, char> > p; for (int i = 0; i < n - 1; i++) { p.insert({c[i], c[i + 1]}); } vector<pair<pair<char, char>, int> > z; for (auto i = p.begin(); i != p.end(); i++) { z.push_back({{(*i).first, (*i).second}, 0}); } vector<int> count(p.size(), 0); for (int i = 0; i < n - 1; i++) { for (auto j = z.begin(); j != z.end(); j++) { if ((*j).first.first == c[i] && (*j).first.second == c[i + 1]) { (*j).second++; } } } vector<int> temp; int j = 0; for (auto i = z.begin(); i != z.end(); i++) { temp.push_back((*i).second); } int max_index = max_element(temp.begin(), temp.end()) - temp.begin(); cout << z[max_index].first.first << z[max_index].first.second; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, i, j, cnt = 0, mx = 0; string s, ans; cin >> n >> s; for (i = 0; i < n - 1; i++) { cnt = 0; string sub = s.substr(i, 2); for (j = i; j <= n - 2; j++) { if (s.substr(j, 2) == sub) cnt++; } mx = max(mx, cnt); if (mx == cnt) ans = sub; } mx = max(mx, cnt); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; string itosm(long long x) { if (x == 0) return "0"; string ans = ""; while (x > 0) { ans += ((x % 10) + '0'); x /= 10; } reverse(ans.begin(), ans.end()); return ans; } long long stoim(string str) { long long ans = 0; long long k = 1; int p = 0; if (str[0] == '-') p++; for (int i = str.length() - 1; i >= p; i--) { ans += (str[i] - '0') * k; k *= 10; } return ans; } const long long infll = 1e18 + 3; const int inf = 1009000999; const long double eps = 1e-7; const int maxn = 1e6 + 1146; const int baseint = 1000200013; const long long basell = 1e18 + 3; const long double PI = acos(-1.0); const long long mod = 1e9 + 9; void solve() { int n; cin >> n; string s; cin >> s; string ans = "AA"; int f = 0; for (char c1 = 'A'; c1 <= 'Z'; c1++) { for (char c2 = 'A'; c2 <= 'Z'; c2++) { int ff = 0; for (int i = 1; i < n; i++) { if (s[i - 1] == c1 && s[i] == c2) ff++; } if (ff > f) { f = ff; ans = c1; ans += c2; } } } cout << ans; } int main() { ios_base::sync_with_stdio(0); ; cin.tie(0); cout.tie(0); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n; string s, s1; cin >> n >> s; long long ans = 0; for (int i = 0; i < n - 1; i++) { string st = s.substr(i, 2); long long cnt = 0; for (long long j = 0; j < n - 1; j++) { string st2 = s.substr(j, 2); if (st == st2) { cnt++; } } if (cnt > ans) { ans = cnt; s1 = st; } } cout << s1; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string str; cin >> str; char s1, s2, s3 = str[0], s4 = str[1]; int k_max = 0, k = 0; int z = 0; while (z != str.size() - 1) { s1 = str[z]; s2 = str[z + 1]; for (int i = z + 1; i <= str.size() - 1; i++) { if (str[i] == s1 & str[i + 1] == s2) { k++; } } if (k > k_max) { k_max = k; s3 = s1; s4 = s2; } k = 0; z++; } cout << s3 << s4; }
#include <bits/stdc++.h> using namespace std; map<string, int> mp; int main() { int n, c = 0; cin >> n; string s; cin >> s; string res; for (int i = 0; i < n - 1; i++) { string temp; temp.push_back(s[i]); temp.push_back(s[i + 1]); mp[temp]++; c = max(c, mp[temp]); if (c == mp[temp]) res = temp; } cout << res; return 0; }
#include <bits/stdc++.h> char a[1005]; int sum[50][50] = {}; int main() { int n; scanf("%d", &n); scanf("%s", a); for (int i = 0; i < n - 1; i++) { int x, y; x = a[i] - 'A'; y = a[i + 1] - 'A'; sum[x][y]++; } int mmax = 0, flag = 0, MMAX1, MMAX2; for (int i = 0; i < 28; i++) { for (int j = 0; j < 28; j++) { if (sum[i][j] > mmax) { mmax = sum[i][j]; MMAX1 = i; MMAX2 = j; } } } char w, e; w = MMAX1 + 'A'; e = MMAX2 + 'A'; printf("%c%c", w, e); return 0; }
#include <bits/stdc++.h> using namespace std; int n, i, mx; string s, t, q; map<string, int> a; int main() { cin >> n >> s; for (i = 0; i < s.size(); i++) { t = ""; t += s[i]; t += s[i + 1]; a[t]++; if (a[t] > mx) { mx = a[t]; q = t; } } cout << q; }
#include <bits/stdc++.h> using namespace std; int main() { char now1, now2; int k; string s; cin >> k; cin >> s; int maxn = 0; for (char i = 'A'; i <= 'Z'; i++) { for (char j = 'A'; j <= 'Z'; j++) { int ans = 0; for (int l = 0; l < k - 1; l++) { if (s[l] == i && s[l + 1] == j) ans++; } if (ans > maxn) maxn = ans, now1 = i, now2 = j; } } cout << now1 << now2; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; vector<string> ts; vector<int> count; for (int i = 0; i < n - 1; i++) { string tsi = s.substr(i, 2); bool exists = false; for (int j = 0; j < ts.size(); j++) { if (ts[j].compare(tsi) == 0) { exists = true; count[j]++; } } if (exists == false) { ts.push_back(tsi); count.push_back(1); } } int max = 0; int maxInd = 0; for (int i = 0; i < count.size(); i++) { if (count[i] > max) { max = count[i]; maxInd = i; } } cout << ts[maxInd] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n; string s, t; string ans; int anst, tmp; int main() { cin >> n >> s; tmp = -1; for (int i = 0; i < n - 1; i++) { int cnt = 0; t = s.substr(i, 2); for (int j = 0; j < n - 1; j++) { if (t[0] == s[j] && t[1] == s[j + 1]) cnt++; } if (cnt > tmp) { ans = t; tmp = cnt; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; signed main() { long long n; string s; cin >> n; cin >> s; vector<string> d; for (long long i = 1; i < n; i++) { string s1 = ""; s1 += s[i - 1]; s1 += s[i]; d.push_back(s1); } long long m = 0; string ans = ""; for (long long i = 0; i < d.size(); i++) { long long k = 0; for (long long j = 0; j < n - 1; j++) { if (s.substr(j, 2) == d[i]) { k++; } } if (k > m) { ans = d[i]; m = k; } } cout << ans; }