URAL 1723. Sandro's Book
2015-03-22 09:01
363 查看
1723. Sandro's Book
Time limit: 0.5 secondMemory limit: 64 MB
It's been quite a number of years since Lich Sandro retired. Sometimes in the evenings, when he feels especially lonely, he takes a book that was presented to him by his student magicians on the occasion
of his retirement.
This evening the great magician is also reading the book. One of the chapters describes Sandro's famous discovery: he invented a universal spell many years ago. Any substring (a few consecutive symbols
of the string) of the universal spell is also a spell, and its power is equal to the number of times this spell is encountered in the universal spell (for example, the string “ue” encounters in the string “queue” twice, and the string “aba” encounters in the
string “abababa” three times).
Sandro has a lot of free time now and he wants to find the most powerful spell. Help Sandro do it.
Input
The only input line contains the universal spell invented by Sandro. The spell is a non-empty string consisting of lowercase English letters with length at most 50.Output
Output any of the most powerful spells, according to Sandro's definition.Sample
input | output |
---|---|
tebidohtebidoh | tebidoh |
解析:题意描述的不清楚,没有讲可以输出任意一个。。。其实只需要找出现最多的字符就行了。
AC代码:
#include <cstdio> #include <string> #include <iostream> #include <cstring> using namespace std; int c[128]; int main(){ #ifdef sxk freopen("in.txt", "r", stdin); #endif //sxk string s; while(cin>>s){ memset(c, 0, sizeof(c)); int len = s.size(), foo = 0; for(int i=0; i<len; i++){ c[ s[i] ] ++; if(c[s[foo]] < c[s[i]]){ foo = i; } } cout<<s[foo]<<endl; } return 0; }
相关文章推荐
- ural 1723 Sandro's Book
- 字符串专项:Ural 1723
- URAL 1723 Sandro's Book
- URAL 1723. Sandro's Book(数学啊)
- Ural 1723. Sandro's Book
- URAL 1750 Pakhom and the Gully 计算几何+floyd
- URAL 1893
- URAL 1457. Heating Main
- 【物理问题】URAL - 1939 First Seal
- ural 1026. Questions and Answers 查询
- ural 1119. Metro dp
- CJOJ 1976 二叉苹果树 / URAL 1018 Binary Apple Tree(树型动态规划)
- URAL1519 Formula 1(插头dp的基础题 ——详细解释)
- URAL - 1004 Sightseeing Trip(最小环)
- UESTC1723 篝火晚会(组合数学)
- URAL-1101. Robot in the Field
- URAL 1011|Conductors|暴力
- URAL 1083|Factorials!!!|暴力
- URAL 1141(扩展欧几里德+欧拉函数)
- 【一般图最大匹配】URAL - 1099 Work Scheduling