Codeforces Round #479 (Div. 3) B. Two-gram
原题代码: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的更多相关文章
- Codeforces Round #479 (Div. 3) A. Wrong Subtraction
题目网址:http://codeforces.com/contest/977/problem/A 题解:给你一个数n,进行k次变换,从末尾开始-1,512变成511,511变成510,510会把0消掉 ...
- Codeforces Round #479 (Div. 3) C. Less or Equal
题目地址:http://codeforces.com/contest/977/problem/C 题解:给一串数组,是否找到一个数x,找到k个数字<=x,找到输出x,不能输出-1.例如第二组,要 ...
- Codeforces Round #479 (Div. 3) F. Consecutive Subsequence (简单dp)
题目:https://codeforces.com/problemset/problem/977/F 题意:一个序列,求最长单调递增子序列,但是有一个要求是中间差值都是1 思路:dp,O(n)复杂度, ...
- Codeforces Round #479 (Div. 3)解题报告
题目链接: http://codeforces.com/contest/977 A. Wrong Subtraction 题意 给定一个数x,求n次操作输出.操作规则:10的倍数则除10,否则减1 直 ...
- Codeforces Round #479 (Div. 3) 题解 977A 977B 977C 977D 977E 977F
A. Wrong Subtraction 题目大意: 定义一种运算,让你去模拟 题解: 模拟 #include <iostream> #include <cstdio> ...
- Codeforces Round #479 (Div. 3)题解
CF首次推出div3给我这种辣鸡做,当然得写份博客纪念下 A. Wrong Subtraction time limit per test 1 second memory limit per test ...
- Codeforces Round #479 (Div. 3)
手速场2333,这群人贼牛逼!手速贼快! A. Wrong Subtraction time limit per test 1 second memory limit per test 256 m ...
- E. Cyclic Components (DFS)(Codeforces Round #479 (Div. 3))
#include <bits/stdc++.h> using namespace std; *1e5+; vector<int>p[maxn]; vector<int&g ...
- Codeforces Round #479 (Div. 3)解题代码
A. Wrong Subtraction #include <bits/stdc++.h> using namespace std; int main() { int n,k; cin&g ...
随机推荐
- JDK的命令行工具系列 (三) jhat、jstack
jhat: heapdump文件分析工具 在前两篇系列文章JDK的命令行工具系列 (一) jps.jstat.JDK的命令行工具系列 (二) javap.jinfo.jmap中, 我们已经介绍过了jp ...
- spring boot 学习笔记(一)之前端文件配置
一.叙述 spring boot 由于是内置的tomcat ,因此其在独立运行的时候,是不需要单独安装 tomcat,这使其前端文件(CSS.JS.html)等放置的位置与war中的不同. 二.常见配 ...
- gitee+hexo搭建个人博客
通过gitee和hexo搭建个人博客 首先准备软件: git (提供命令git) git官网 notepad++(方便编辑)notepad++官网 nodejs(hexo依赖)nodejs官网 7z( ...
- Python pip包管理器安装第三方库超时解决方案
一.国内镜像安装 使用方法:pip install --index 镜像网站 第三方库名 二.镜像网站 http://pypi.douban.com/simple/ 豆瓣 http://mirrors ...
- java支付宝app支付-代码实现
1.我们需要在支付宝商户平台配置好,取到四个参数如下(这是支付宝官方配置地址):https://www.cnblogs.com/fuzongle/p/10217144.html 合作身份者ID:123 ...
- Java 通过反射改变私有变量的值
直接上代码 import java.lang.reflect.Field; public class Main { public static void main(String[] args ...
- 【科研民工笔记2】Ubuntu 16.04 安装nvidia驱动
我的主机是2060的显卡,用的是安装在U盘中的Ubuntu,开机进入后,因为没有安装驱动,所以界面看以来比较大. 通过手动方式,成功安装驱动,最终成功的方案使用的是run文件安装的方式. 1.手动下载 ...
- 建立第一个G2图表
Step1:引进G2脚本 方法一:引入在线脚本 <script src="https://gw.alipayobjects.com/os/lib/antv/g2/3.4.10/dist ...
- (三)c#Winform自定义控件-有图标的按钮
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- Zabbix-绘制动态拓扑图基础篇
一.实验环境 1.1 zabbix 4.0.2 二.实验需求介绍 公司希望网络拓扑能够动态反应物理接口的状态或者业务的状态,希望将网络拓扑显示到大屏上 三.Zabbix在绘制拓扑的优缺点 3.1 优点 ...