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. 关于sql语句引发的404错误

    今天分享个小问题,也是今天在项目中遇到的,希望对遇到相关问题的朋友有所帮助. 使用工具:(相关的) mybatis,spring-mvc,mysql 问题原因: 我在mybatis的mapper文件中 ...

  2. python基础之条件循环语句

    前两篇说的是数据类型和数据运算,本篇来讲讲条件语句和循环语句. 0x00. 条件语句 条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块. 可以通过下图来简单了解条件语 ...

  3. C++格式化输出的好东西

    s = FormatFloat("0.######", d); 最多保留6位s = FormatFloat("0.000000", d); 始终保留6位s = ...

  4. Tomcat启动错误【Error listenerStart】

    今天启动Tomcat启动不了,报以下错: org.apache.catalina.core.StandardContext startInternal SEVERE: Error listenerSt ...

  5. Win7 32位系统下Sublime text 3的安装以及配置C/C++、java、python的开发环境方法

    本人初学者,此文仅是对这几天鼓捣subime text 3一点微不足道的经验总结,如有明显错误,欢迎指正! 好了,废话少说,进入正题,之前编程java一直用的是eclipse,java的主流IDE,后 ...

  6. python邮件SMTP的GUI编程

    写的是python中smtp的gui编程,用的163邮箱给qq邮箱发送邮件做测试,如果你发现你的发送失败,试着用以下方法解决: 1.网页登陆你的邮箱,设置中查看smtp是否开启,比如163邮箱的smt ...

  7. 考了3年,工作四年,零基础在职终于拿到CFA证书

    大家都知道CFA Charterholder是独有的全球公认的投资管理从业人员高职业水平和道德水准的有力证明,是金融界卓越专业成就的象征:CFA资格强调和遵循极其严格的职业操守和道德准则,世界各主要发 ...

  8. ASP.NET没有魔法——为什么使用ASP.NET

    ASP.NET是什么? ASP.NET是一个使用HTML.CSS.Javascript来构建动态网站或者网站应用程序的Web框架,并且也可以使用它来构建web API和实时通信技术如web soket ...

  9. DataRow和DataRowView的区别

    可以将DataView同数据库的视图类比,不过有点不同,数据库的视图可以跨表建立视图,DataView则只能对某一个DataTable建立视图. DataView一般通过DataTable.Defau ...

  10. 使用Canvas制作时钟动画

    复习Javascript到Canvas的知识点,看到一个使用Canvas绘制的静态时钟例子,便想将其变成动态显示系统时间的时钟动画.另外再配上数字显示的时钟,一个小的时钟模块的诞生了!目前的界面还比较 ...