HDU 5578 Friendship of Frog 水题
Friendship of Frog
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=5578
Description
N frogs from different countries are standing in a line. Each country is represented by a lowercase letter. The distance between adjacent frogs (e.g. the 1st and the 2nd frog, the N−1th and the Nth frog, etc) are exactly 1. Two frogs are friends if they come from the same country.
The closest friends are a pair of friends with the minimum distance. Help us find that distance.
Input
First line contains an integer T, which indicates the number of test cases.
Every test case only contains a string with length N, and the ith character of the string indicates the country of ith frogs.
⋅ 1≤T≤50.
⋅ for 80% data, 1≤N≤100.
⋅ for 100% data, 1≤N≤1000.
⋅ the string only contains lowercase letters.
Output
For every test case, you should output "Case #x: y", where x indicates the case number and counts from 1 and y is the result. If there are no frogs in same country, output −1 instead.
Sample Input
2
abcecba
abc
Sample Output
Case #1: 2
Case #2: -1
HINT
题意
给你一个字符串,然后问你相距最近的相同字符串的长度是多少
题解:
水题,暴力n^2去扫就好了
代码:
- #include<iostream>
- #include<stdio.h>
- using namespace std;
- string s;
- int main()
- {
- int t;scanf("%d",&t);
- for(int cas=;cas<=t;cas++)
- {
- cin>>s;
- int n=s.size();
- int ans = ;
- for(int i=;i<n;i++)
- for(int j=i+;j<n;j++)
- if(s[i]==s[j])
- ans = min(ans,j-i);
- if(ans==)ans=-;
- printf("Case #%d: %d\n",cas,ans);
- }
- }
HDU 5578 Friendship of Frog 水题的更多相关文章
- Friendship of Frog(水题)
Friendship of Frog Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- hdu 5578 Friendship of Frog(multiset的应用)
Problem Description N frogs . Two frogs are friends if they come from the same country. The closest ...
- hdu 5578 Friendship of Frog
题意:给定一行字符串(都是小写字母),每一个字符都代表一只青蛙以及其国籍,若字符串中出现两个字符相同,则这两个字符所代表的青蛙来自同一国度,可称之为好朋友. 现在需要找到距离最近的好朋友并输出他们的距 ...
- HDU 5590 ZYB's Biology 水题
ZYB's Biology Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid ...
- HDU 5538 L - House Building 水题
L - House Building Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...
- HDU 4584 Building bridges (水题)
Building bridges Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) ...
- hdu 1005:Number Sequence(水题)
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- hdu 1018:Big Number(水题)
Big Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- hdu 2041:超级楼梯(水题,递归)
超级楼梯 Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Su ...
随机推荐
- java 地址记录
java在线API地址 http://docs.oracle.com/javase/7/docs/api/
- Matlab命令——目录操作(windows&Linux)
Matlab命令——目录操作(windows&Linux) 1. filesep用于返回当前平台的目录分隔符,Windows是反斜杠(\),Linux是斜杠(/).有时此命令结合ispc命令使 ...
- 新霸哥带你进入java的世界
新霸哥从近期大家的留言中注意到了大家对基础知识比较重视,很多的朋友希望多讲一些入门的知识,为了满足广大开发爱好者的需求,新霸哥决定从最基础的做起,一点一点的帮助大家一起走进云计算的世界.下面新霸哥首先 ...
- 使用最小堆来完成k路归并 6.5-8
感谢:http://blog.csdn.net/mishifangxiangdefeng/article/details/7668486 声明:供自己学习之便而收集整理 题目:请给出一个时间为O(nl ...
- Android 相关
ADT 下载更新 http://www.oschina.net/question/1463998_220998 更改包名后,资源文件不更新 AndroidMainfast.xml文件,有package ...
- 安卓手机修改hosts攻略-摘自网络
Android手机是和Google帐号紧密联系的,由于$^&情况,很多时候Google帐号无法登录,导致Android市场无法使用.在电脑上我们通过修改Hosts方法可以解决Google帐号的 ...
- js运动 模仿淘宝幻灯
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- jBox使用方法
1.引入jquery文件 2.引入css和jBox文件 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml& ...
- 一个效果很华丽的仿桌面APP,却胜似Launcher
开发Android APP的同学是否对于Launcher实现的绚丽效果而痴迷呢?什么,连Android Launcher是什么都不知道.好吧,拿起侬的手机,在解锁后的首页界面上左右滑动滑动,体验体验, ...
- Prefabs
[Prefabs] A Prefab is a type of asset -- a reusable GameObject stored in Project View. Prefabs can b ...