题目链接:Friendship of Frog
题目大意:给你一个字符串,问所有的同一个字符两两最近之间距离的最近距离
题目思路:开个map记录以下就好了
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int T;
char str[1005];
scanf("%d",&T);
for(int Case = 1;Case <= T;Case++){
map<char,int>mp;
int minn = 0x3f3f3f3f;
scanf("%s",str);
int len = strlen(str);
for(int i = 0;i < len;i++){
if(mp[str[i]] == 0) mp[str[i]] = i;
else minn = min(minn,i-mp[str[i]]),mp[str[i]] = i;
}
printf("Case #%d: %d\n",Case,minn == 0x3f3f3f3f?-1:minn);
}
return 0;
}