| ||||||||||
| 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 | |||||||||
用100判断说明数据水,看我巧妙用set的find!#include<string.h>
#include<stdio.h>
#include<set>
#include<string>
#include<vector>
#include<list>
#include<string.h>
#include <algorithm>
#include<iostream>
using namespace std;
set<string>Set;
bool flag;
int main()
{
int t,cas=1;
cin>>t;
while(t--){
printf("%d ",cas++);
flag=false;
Set.clear();
int sum=0;
int len;
string a,b,s,s1;
cin>>len>>a>>b>>s;
int k=0;
s1=s;
for(int i=0;i<len;i++)
s1[k++]=b[i],s1[k++]=a[i];
while(1){
Set.insert(s1);
sum++;
if(s1==s) {printf("%d\n",sum);flag=true;break;}
else{
int k=0,l=1;
a.assign(s1,0,len);
b.assign(s1,len,len);
for(int i=0;i<len;i++)
s1[k++]=b[i],s1[k++]=a[i];
if(Set.find(s1)!=Set.end()) break;
}
}
if(!flag) printf("-1\n");
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator