Problem Statement for StringDup

Problem Statement

    
Create a class called StringDup. Given a string made up of ONLY letters and
digits, determine which character is repeated the most in the string ('A' is
different than 'a'). If there is a tie, the character which appears first in
the string (from left to right) should be returned. Examples : aaiicccnn = c
aabbccdd = a
ab2sbf2dj2skl = 2 Here is the method signature : public char getMax(String input); We will check to make sure that the input contains only letters and digits (no
punctuation marks or spaces).
 

Definition

    
Class: StringDup
Method: getMax
Parameters: String
Returns: char
Method signature: char getMax(String param0)
(be sure your method is public)
    
 

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.

/*
* @Author: LyuCheng
* @Date: 2017-05-13 20:02:42
* @Last Modified by: LyuCheng
* @Last Modified time: 2017-05-13 20:40:49
*/
/*
题意:给你一个只有字母和数字组成的字符串,让你输出出现次数最多的字符,如果最多数量的相同
就输出最先出现的那个字符 思路:结构体加映射,结构体记录字符出现的顺序和出现的次数,然后按照次数为第一优先级,顺序
第二优先级进行排序输出。
*/
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
struct node{
int rank;
int res;
char str;
node(){}
node(int _rank,int _res,char _str){
rank=_rank;
res=_res;
str=_str;
}
bool operator <(const node &other) const{
if(res==other.res) return rank<other.rank;
else return res>other.res;
}
};
int pos=;//字符的种类
node vis[];
char str[];
void init(){
pos=;
for(int i=;i<;i++){
vis[i].str='\0';
vis[i].res=;
vis[i].rank=;
}
}
int main(){
freopen("in.txt","r",stdin);
while(scanf("%s",str)!=EOF){
init();
int n=strlen(str);
for(int i=;i<n;i++){
if(str[i]>=''&&str[i]<=''){
if(vis[str[i]-''].rank==){
vis[str[i]-''].str=str[i];
vis[str[i]-''].rank=pos++;
vis[str[i]-''].res++;
}else{
vis[str[i]-''].res++;
}
}else if(str[i]>='a'&&str[i]<='z'){
if(vis[str[i]-'a'+].rank==){
vis[str[i]-'a'+].str=str[i];
vis[str[i]-'a'+].rank=pos++;
vis[str[i]-'a'+].res++;
}else{
vis[str[i]-'a'+].res++;
}
}else{
if(vis[str[i]-'A'+].rank==){
vis[str[i]-'A'+].str=str[i];
vis[str[i]-'A'+].rank=pos++;
vis[str[i]-'A'+].res++;
}else{
vis[str[i]-'A'+].res++;
}
}
}
sort(vis,vis+);
printf("%c\n",vis[].str);
}
return ;
}

StringDup(理论AC)的更多相关文章

  1. 【一坨理论AC的题】Orz sxy大佬

    1.UVA10891 Game of Sum 2.LA4254 Processor . 3.UVA10905 Children's Game 4.UVA11389 The Bus Driver Pro ...

  2. 尝试一下LLJ大佬的理论AC大法

    1.BZOJ 3522 Poi2014 Hotel DFS 给定一棵树,求有多少无序三元组(x,y,z)满足x,y,z互不相等且Dis(x,y)=Dis(y,z)=Dis(x,z) 枚举中心点,分别d ...

  3. Codeforces Round #384 (Div. 2) ABCD

    一场比较简单的div2 电脑出了点问题 所以在比赛中理论ac了ACD 除了爆int这种事情之外.. A 一个人想从a到b 移动的花费这么定义 如果初始点和到达点类型相同 就不花钱 反之花距离差的绝对值 ...

  4. Codeforces Round #383 _python作死系列

    A. Arpa's hard exam and Mehrdad's naive cheat 题意求1378的n次方的最后一位,懒的写循环节 瞎快速幂 py3 int和LL 合并为int了 def q_ ...

  5. HDU4945 2048(dp)

    先是看错题意..然后知道题意之后写了发dp..无限TLE..实在是不知道怎么优化了,跑了遍数据是对的,就当作理论AC掉好了.. #pragma warning(disable:4996) #inclu ...

  6. 我的EC-final总结

    by.Max EC-final正式结束,也预示着我大学ICPC旅程的结束.回来睡了一天,现在也可以总结一下了 被告知参赛: 本来以为就会这样告别ACM-ICPC,没想到半个月前徐老师告诉我们SHU给我 ...

  7. 【2012长春区域赛】部分题解 hdu4420—4430

    这场比赛特点在于两个简单题太坑,严重影响了心情..导致最后只做出两题....当然也反映出心理素质的重要性 1002: 题意:一个矩阵b[n][n]通过数组 a[n]由以下规则构成,现在已知b[n][n ...

  8. 2015 ACM / ICPC 亚洲区域赛总结(长春站&北京站)

    队名:Unlimited Code Works(无尽编码)  队员:Wu.Wang.Zhou 先说一下队伍:Wu是大三学长:Wang高中noip省一:我最渣,去年来大学开始学的a+b,参加今年区域赛之 ...

  9. 江西理工大学南昌校区cool code竞赛

    这次比赛原本就是来打酱油的,想做个签到题就走!一开始不知道1002是签到题,一直死磕1001,WA了四发过了,回头一看Rank,三十名,我靠!看了1001的AC率,在我AC之前只有一个人AC了,当时我 ...

随机推荐

  1. Centos6.7安装chrome

    cd /etc/yum.repos.dwget http://people.centos.org/hughesjr/chromium/6/chromium-el6.repo yum install c ...

  2. MMORPG战斗系统随笔(二)、浅谈场寻路Flow Field PathFinding算法

    转载请标明出处http://www.cnblogs.com/zblade/ 今天给大家带来一篇游戏中寻路算法的博客.去年,我加入一款RTS的游戏项目,负责开发其中的战斗系统,战斗系统的相关知识,属于游 ...

  3. 实例讲解js正则表达式的使用

    前言:正则表达式(regular expression)反反复复学了多次,学了又忘,忘了又学,这次打算把基本的东西都整理出来,加强记忆,也方便下次查询. 学习正则表达式之前首先需要掌握记忆这些基本概念 ...

  4. 基于maven创建和部署Webx项目

    1.准备工作 下载 Webx Maven 项目的目录结构Artifact插件. archetype-webx-quickstart-1.0.tar.gz插件:http://central.maven. ...

  5. 支持向量机SVM(一)

    [转载请注明出处]http://www.cnblogs.com/jerrylead 1 简介 支持向量机基本上是最好的有监督学习算法了.最开始接触SVM是去年暑假的时候,老师要求交<统计学习理论 ...

  6. JavaWeb(五)之JSTL标签库

    前言 前面介绍了EL表达式,其实EL表达式基本上是和JSTL核心标签库搭配一起使用才能发挥效果的.接下来让我们一起来认识一下吧! 在之前我们学过在JSP页面上为了不使用脚本,所以我们有了JSP内置的行 ...

  7. HAProxy安装文档

    HAProxy安装文档 [toc][TOC] 一.环境说明 系统环境:CentOS Linux release 7.2.1511 (Core) 系统内核:3.10.0-327.el7.x86_64 软 ...

  8. Vue使用总结

    好久没更新博客,确实是自己已经懒癌晚期,最近毕业刚工作3个月,公司开发一直在用Vue,自己个人也比较喜欢这个框架,今天就对自己学习到和用到的知识点作一些总结,希望能帮到大家. Vue 知道Vue也一定 ...

  9. Python面试题之python是一种什么语言及优缺点

    1.说说python是一种什么语言? 参考答案:python是一门动态解释性的强类型定义语言 编译型vs解释型 编译型优点:编译器一般会有预编译的过程对代码进行优化.因为编译只做一次,运行时不需要编译 ...

  10. Nunit测试工具使用实例

    前言: 本文主要是介绍了Nunit的基本使用,其中参详了很多已有的文章,由于最近要使用其进行测试,所以对网上的文章做了下整理,同时加入了一些自己的实践. NUnit的属性 TestFixture 它标 ...