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

用next_permutation,能过样例但是一直WA,要死要死。。。

Posted by YZLZZ at 2017-07-18 14:50:42 on Problem 1318
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>

using namespace std;

int main()
{
    int len,flag;
     freopen("input.txt","r",stdin);
    string dict[101],word;
    len=0;
    while(1)
    {
        cin>>dict[len];

        if(dict[len]=="XXXXXX")
            break;
             len++;
    }
    sort(dict,dict+len);
    //cout<<"1"<<endl;
    while(1)
    {
        cin>>word;
        flag=0;
        if(word=="XXXXXX")
            break;


        if(word.size()==1)
            {
                 for(int i=0; i<len; i++)
            {
                if(dict[i].size()!=word.size())
                    continue;

                if(word==dict[i])
                {
                    cout<<dict[i]<<endl;
                    flag++;
                }
            }
            }
            else if(word.size()==2)
            {
                for(int i=0; i<len; i++)
                {
                    if(dict[i].size()!=word.size())
                        continue;

                    if(word==dict[i])
                    {
                        cout<<dict[i]<<endl;
                        flag++;
                    }

                }
            reverse(word.begin(),word.end());
            for(int i=0; i<len; i++)
            {
                if(dict[i].size()!=word.size())
                    continue;

                if(word==dict[i])
                    cout<<dict[i]<<endl;
                    flag++;
                }

            }




        else if(word.size()>=3)
        {
            sort(word.begin(),word.end());

            while(next_permutation(word.begin(),word.end()))
                for(int i=0; i<len; i++)
                {
                    if(dict[i].size()!=word.size())
                        continue;

                    if(word==dict[i])
                    {
                        cout<<dict[i]<<endl;
                        flag++;
                    }
                }
        }
        if(flag==0)
            cout<<"NOT A VALID WORD"<<endl;
        cout<<"******"<<endl;
  }
    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