原题代码:http://codeforces.com/contest/977/problem/B

题解:有n个字符组成的字符串,输出出现次数两个字符组合。例如第二组样例ZZ出现了两次。

方法:比较无脑,本来想用map,发现不会用map排序,字符串最长100,然后我选择了暴力。TAT建立一个结构体,把两个字母前后放到a,b,然后统计这样情况出现的次数,最后排序就好啦~

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#include<map>
#include<vector>
#include<set>
#include<queue>
using namespace std;
struct sub
{
char a;
char b;
int count;
sub()
{
count = ;
}
}str[];
bool compare(sub x, sub y)
{
return x.count > y.count;
}
int main()
{
int n;
char s[];
cin >> n;
cin >> s;
str[].a = s[];
str[].b = s[];
str[].count = ;
int sum = ;
for (int i = ; i < n - ; i++)
{
int flag = ;
for (int j = ; j < i; j++)
{
if (str[j].a == s[i] && str[j].b == s[i + ])
{
flag = ;
str[j].count++;
continue;
}
}
if (flag == )
{
str[sum].a = s[i];
str[sum].b = s[i + ];
str[sum].count++;
sum++;
}
}
sort(str, str + n + , compare);
printf("%c%c\n", str[].a, str[].b);
return ;
}

Codeforces Round #479 (Div. 3) B. Two-gram的更多相关文章

  1. Codeforces Round #479 (Div. 3) A. Wrong Subtraction

    题目网址:http://codeforces.com/contest/977/problem/A 题解:给你一个数n,进行k次变换,从末尾开始-1,512变成511,511变成510,510会把0消掉 ...

  2. Codeforces Round #479 (Div. 3) C. Less or Equal

    题目地址:http://codeforces.com/contest/977/problem/C 题解:给一串数组,是否找到一个数x,找到k个数字<=x,找到输出x,不能输出-1.例如第二组,要 ...

  3. Codeforces Round #479 (Div. 3) F. Consecutive Subsequence (简单dp)

    题目:https://codeforces.com/problemset/problem/977/F 题意:一个序列,求最长单调递增子序列,但是有一个要求是中间差值都是1 思路:dp,O(n)复杂度, ...

  4. Codeforces Round #479 (Div. 3)解题报告

    题目链接: http://codeforces.com/contest/977 A. Wrong Subtraction 题意 给定一个数x,求n次操作输出.操作规则:10的倍数则除10,否则减1 直 ...

  5. Codeforces Round #479 (Div. 3) 题解 977A 977B 977C 977D 977E 977F

    A. Wrong Subtraction 题目大意:   定义一种运算,让你去模拟 题解:   模拟 #include <iostream> #include <cstdio> ...

  6. Codeforces Round #479 (Div. 3)题解

    CF首次推出div3给我这种辣鸡做,当然得写份博客纪念下 A. Wrong Subtraction time limit per test 1 second memory limit per test ...

  7. Codeforces Round #479 (Div. 3)

    手速场2333,这群人贼牛逼!手速贼快!   A. Wrong Subtraction time limit per test 1 second memory limit per test 256 m ...

  8. E. Cyclic Components (DFS)(Codeforces Round #479 (Div. 3))

    #include <bits/stdc++.h> using namespace std; *1e5+; vector<int>p[maxn]; vector<int&g ...

  9. Codeforces Round #479 (Div. 3)解题代码

    A. Wrong Subtraction #include <bits/stdc++.h> using namespace std; int main() { int n,k; cin&g ...

随机推荐

  1. 【Android】error: Error retrieving parent for item: No resource found that matches the given name 'Theme.Sherlock.Light.NoActionBar'.

    问题: res 文件夹下的 values 下的 styles.xml <style name="Sherlock.Light.NoActionBar" parent=&quo ...

  2. 【python-django后端开发】Redis缓存配置使用详细教程!!!

    官方查阅资料:https://django-redis-chs.readthedocs.io/zh_CN/latest/ 1. 安装django-redis扩展包 1.安装django-redis扩展 ...

  3. Mobile game forensics

    My friend Carrie'd like to know "Garena 传说对决" violates any mobile risks such as insecure d ...

  4. python_0基础学习_day01

    Python是一门动态解释型的强类型定义语言 一.变量 变量命名规则 由数字.字母.下划线组成 不能以数字开头 要具有描述性 要区分大小写 禁止使用python的关键字(在pycharm中关键字明明变 ...

  5. spring-boot项目的docker集成化部署(一)

    目录 spring-boot项目的docker集成化部署 前言 基本思路与方案 基本步骤 准备源码 服务器和基础环境 结语 1. 本文总结: 2. 后期优化: spring-boot项目的docker ...

  6. vscode c 语言 win10

    在看 CSAPP 一些课程,一些c 语言的小程序的例子,想跑起来试试,用一个DEV  c++  简单上手,但这是一个上古的IDE, 前端开发中的代码不全,语法高亮,都不太好,就想着为什么不折腾一下 V ...

  7. Unity进阶之:Shader渲染

    版权声明: 本文原创发布于博客园"优梦创客"的博客空间(网址:http://www.cnblogs.com/raymondking123/)以及微信公众号"优梦创客&qu ...

  8. 状压DP概念 及例题(洛谷 P1896 互不侵犯)

    状压DP 就是状态压缩DP.所谓状态压缩,就是将一些复杂的状态压缩起来,一般来说是压缩为一个二进制数,用01来表示某一元素的状态. 比如一排灯泡(5个) 我们可以用一串二进制01串来表示他们的状态 1 ...

  9. 2321. 【NOIP普及组T1】方程

    2321. [NOIP普及组T1]方程 时间限制: 1000 ms  空间限制: 262144 KB 题目描述

  10. python(自用手册)三

    第三章 基础 3.1编码初识 ascii 256字母没有中文 一个字节 8位 gbk 中国 中文2字节 16位 英文1字节8位 unicode 万国码 前期 2字节 8位 后期变成4个字节 32位 u ...