Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## map + string

Posted by 20053565 at 2010-04-27 18:16:41 on Problem 3007
In Reply To:哪位大哥给个stl代码吖? 性感的set+string和vector+unique都超时了,无语` Posted by:lijinwu at 2010-04-27 07:44:12
#include <stdio.h>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

int len;

map <string,int> h;

int main()
{
int m, i, j, ans;
string t, p, q;
char str[75];

scanf("%d",&m);
while (m > 0)
{
m--;
ans = 1;
scanf("%s",str);
len = strlen(str);
h.clear();
t = str;
h[t] = 1;
for (i = 1; str[i]; i++)
{
t = "";p = "";
for (j = 0; j < i; j++)
{
t += str[j];
}
for (j = len-1; j >= i; j--)
{
t += str[j];
p += str[j];
}
for (j = 0; j < i; j++)
{
p += str[j];
}
if(h[t]==0)
{
h[t] = 1;
ans++;
}
if(h[p]==0)
{
h[p] = 1;
ans++;
}
t = "";p = "";
for(j = i; j < len; j++)
{
t += str[j];
}
for(j = i-1; j >= 0; j--)
{
t += str[j];
p += str[j];
}
for(j = i; j < len; j++)
{
p += str[j];
}
if(h[t]==0)
{
h[t] = 1;
ans++;
}
if(h[p]==0)
{
h[p] = 1;
ans++;
}
t = "";p = "";
for(j = i-1; j >= 0; j--)
{
t += str[j];
}
for(j = len-1; j >= i; j--)
{
p += str[j];
}
q = p+t;
if(h[q]==0)
{
h[q] = 1;
ans++;
}
q = t+p;
if(h[q]==0)
{
h[q] = 1;
ans++;
}
t = "";
for(j = i; j < len; j++)
{
t += str[j];
}
for(j = 0; j < i; j++)
{
t += str[j];
}
if(h[t]==0)
{
h[t] = 1;
ans++;
}
}
printf("%d\n",ans);
}
return 0;
}

Followed by: