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 |
为什么老是超时呢//#include "stdafx.h" #include<iostream> #include<string> #include<set> using namespace std; int main(int argc, char* argv[]) { string str; char s[85]; int n; scanf("%d\n",&n); int i,j,k; while(gets(s)) { str=s; int l=str.length(); if(l==2) { if(str[0]==str[1])printf("1\n"); else printf("2\n"); continue; } set<string>se; //构造所有字串 for(i=1;i<l;i++)//终点 { string zc1,zc10;//前子串 string zc2,zc20;//后子串 string str2;//可行子串 for(j=0,k=i-1;j<i;j++,k--)//构造前子串 { zc10+=str[j]; zc1+=str[k]; } for(j=i,k=l-1;j<l;j++,k--)//构造后子串 { zc20+=str[j]; zc2+=str[k]; } // reverse(zc1.begin(),zc1.end()); //reverse(zc2.begin(),zc2.end()); //8种组合方式 //str2=zc10+zc20; se.insert(str); str2=zc10+zc2; se.insert(str2); str2=zc1+zc20; se.insert(str2); str2=zc1+zc2; se.insert(str2); str2=zc20+zc10; se.insert(str2); str2=zc20+zc1; se.insert(str2); str2=zc2+zc10; se.insert(str2); str2=zc2+zc1; se.insert(str2); }//for printf("%d\n",se.size()); }//while return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator