| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
map + stringIn 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:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator