Hdoj.5578 Friendship of Frog【字符串,暴力】 2015/12/04
来源:互联网 发布:mac如何打开msg文件 编辑:程序博客网 时间:2024/06/11 12:59
Friendship of Frog
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 181 Accepted Submission(s): 130
Problem Description
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 lengthN , 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.
Every test case only contains a string with length
Output
For every test case, you should output "Case #x: y", wherex 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
2abcecbaabc
Sample Output
Case #1: 2Case #2: -1
Source
2015ACM/ICPC亚洲区上海站-重现赛(感谢华东理工)
题意:求两个相同字母间的最小距离,若不存在两个相同的字母,输出-1.
直接暴力求解,从某一字符往后面再找26个字符即可
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int main(){ char s[1010]; int t,ans=1; cin>>t; while(t--){ scanf("%s",s); printf("Case #%d: ",ans++); int l = strlen(s); int dis = l*2; for( int i = 0 ; i < l ; ++i ){ for( int j = 1 ; j <= 26 && i+j < l ; ++j ){ if( s[i] == s[i+j] ){ if( j < dis ) dis = j; break; } } if( dis == 1 ) break; } if( dis == 2*l ) printf("-1\n"); else printf("%d\n",dis); } return 0;}
0 0
- Hdoj.5578 Friendship of Frog【字符串,暴力】 2015/12/04
- hdoj 5578 Friendship of Frog
- hdoj Friendship of Frog 5578 (简单字符串转换)
- HDU 5578 Friendship of Frog 暴力搜索
- HDU 5578 Friendship of Frog(暴力)
- HDU 5578 Friendship of Frog 暴力
- hdoj 5578 Friendship of Frog 【水题】
- 文章标题 HDU 5578 :Friendship of Frog(暴力+map)
- HDU 5578 Friendship of Frog(暴力)——2015ACM/ICPC亚洲区上海站
- hdu 5578 Friendship of Frog
- hdu 5578 Friendship of Frog
- HDU-5578-Friendship of Frog【2015上海赛区】
- HDU-5578-Friendship of Frog【2015上海赛区】(水题)
- hdu 5578 Friendship of Frog(水)
- hdu 5578 Friendship of Frog【水题】
- hdu 5578 Friendship of Frog 水题
- 2015 上海区域赛 Friendship of Frog
- Friendship of Frog
- IOS OC属性、构造函数、封装、继承、多态
- 因子与阶乘
- 【Html】<address>标签,为网页加入地址信息
- 数据结构与算法(单循环链表_约瑟夫问题)
- otsu算法---matlab实现,和一种改进算法
- Hdoj.5578 Friendship of Frog【字符串,暴力】 2015/12/04
- project euler 28
- eclipse打包成apk后出现的错误(please open wifi for debuging )
- 04 BloomFilter
- c++单独编译
- Windows程序设计(Hello,word!)
- project euler 29
- 印度足球之最
- project euler 30