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. Coder的好伙伴Github

    网络越来越发达,各式各样的网盘.云存储也走进日常生活,  在老师的指导下,我第一次接触了GitHub. 什么是Github? Github是一个基于git的代码托管平台,付费用户可以建私人仓库,我们一 ...

  2. ACM-ICPC北京赛区(2017)网络赛_Minimum

    题目9 : Minimum 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a list of integers a0, a1, -, a2^k ...

  3. nodejs 初次链接 mongodb 的详细细节

    时间  2016-06-2613:05:16 在前端的学习也有一段时间了,学习了html,css,javascript,jqery,ajax,php,mysql,学习了这些,了解了一些皮毛,也没有什么 ...

  4. linux/Windows系统如何安装PHP-openssl扩展

    今天倒腾了半天公司的OA办公系统,原来现在很多的smtp服务器是需要ssl方式加密的,而支持ssl需要php加载openssl扩展.所以本文我们将和大家一起分享如何在linux/Windows系统下安 ...

  5. [js高手之路] html5 canvas系列教程 - 状态详解(save与restore)

    本文内容与路径([js高手之路] html5 canvas系列教程 - 开始路径beginPath与关闭路径closePath详解)是canvas中比较重要的概念.掌握理解他们是做出复杂canvas动 ...

  6. SSM之整合Redis

    Redis安装与使用 第一步当然是安装Redis,这里以Windows上的安装为例. 首先下载Redis,可以选择msi或zip包安装方式 zip方式需打开cmd窗口,在解压后的目录下运行redis- ...

  7. 在分布式数据库中CAP原理CAP+BASE

    本篇博文的内容均来源于网络,本人只是整理,仅供学习! 一.关系型数据库 关系型数据库遵循ACID规则 事务在英文中是transaction,和现实世界中的交易很类似,它有如下四个特性: 1.A (At ...

  8. Drying poj3104(二分)

    Drying Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7916   Accepted: 2006 Descriptio ...

  9. Uva 3708 Graveyard

    题意:在周长为10000的圆上等距分布着n个雕塑.现在又有m个新雕塑加入(位置可以随意放),希望所有n+m个雕塑在圆周上均匀分布. 这就需要移动其中一些原有的雕塑.要求n个雕塑移动的距离最小. (2& ...

  10. zoj3211dream city dp 斜率

    Dream City Time Limit: 1 Second      Memory Limit:32768 KB JAVAMAN is visiting Dream City and he see ...