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

用100判断说明数据水,看我巧妙用set的find!

Posted by xx315 at 2015-06-12 12:50:34 on Problem 3087
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator