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 ...
随机推荐
- hexo的环境变量被删除怎么办
这篇文章主要讲在path这一环境变量被删除的情况下,补上哪些环境变量才可以使hexo重新使用. 前两天配置opencv的时候,不小心将环境变量中"path"这一项中的内容给覆盖掉了 ...
- k8s学习02-----kubeadm部署k8s
机器规划 系统配置 三台机器都执行 1.关闭selinux及firewalld sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux ...
- 0x15 字符串
KMP算法 next数组的求法 void calc_next() { next[]=; , j=; i<=n; ++i) { &&a[i]!=a[j+]) j=next[j]; ...
- S3 Select for Java 使用记录
背景 后台基本使用 Amazon 的全家桶(EC2.DynamoDB.S3.Step Fuction 等等)构建.现在需要根据访问者的 IP 确定访问者的国家或地区. 已知: 访问者 IP 一个 ip ...
- android ——通知管理
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle saved ...
- pythonday03数据类型(一)
今日内容 1.整型 2.布尔型 3.字符串 4.补充 5.作业讲解 6,pycharm自动生成头文件 1.整型(int) py2 int/long 32位电脑:-2147483648-21474836 ...
- 使用Prerender.io进行网站预加载
我在自己的项目中是采用的前后端分离的技术,前端用的VUE开发,后端是JAVA开发,tomcat部署,nginx转发,但是VUE开发的项目缺点就是不利于SEO,所以针对SEO做了预加载的操作. 决定采用 ...
- 【POJ - 3255】Roadblocks(次短路 Dijkstra算法)
Roadblocks 直接翻译了 Descriptions Bessie搬到了一个新的农场,有时候他会回去看他的老朋友.但是他不想很快的回去,他喜欢欣赏沿途的风景,所以他会选择次短路,因为她知道一定有 ...
- webgl(three.js)实现室内定位,楼宇bim、实时定位三维可视化解决方案
(写在前面,谈谈物联网展会)上次深圳会展中心举行物联网展会,到了展会一看,80%以上的物联网应用都是在搞RFID,室内定位,我一度怀疑物联网落地方案的方向局限性与市场导向,后来多方面了解才明白,展会上 ...
- 集成Ribbon的客户端调用工具——Feign
什么是Feign? 客户端调用工具 Ribbon+RestTemplate Feign Feign特性: Feign本身包含Ribbon Fegin是一个采用基于接口的注解的声明式客户端调用工具,更加 ...