#12582: WA line 380216


jefflo861104 (unknown)

學校 : 不指定學校
編號 : 62099
來源 : [116.241.161.199]
最後登入時間 :
2024-04-02 19:52:32
d436. 10098 - Generating Fast, Sorted Permutation -- UVa10098 | From: [180.217.151.69] | 發表日期 : 2017-08-15 12:49

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
int a;
cin>>a;
string b[a];
for(int i=0;i<a;i++)
{
cin>>b[i];
sort(b[i].begin(),b[i].end());
do
{
for(int j=0;j<b[i].length();j++)
{
cout<<b[i][j];
}
cout<<endl;
}while(next_permutation(b[i].begin(),b[i].end()));
cout<<endl;
}

return 0;
}

 
#24712: Re:WA line 380216


hsugoya@gmail.com (Мигает cf4?)

學校 : 國立臺北科技大學
編號 : 139476
來源 : [36.226.67.79]
最後登入時間 :
2024-05-31 00:15:30
d436. 10098 - Generating Fast, Sorted Permutation -- UVa10098 | From: [36.224.210.186] | 發表日期 : 2021-03-16 21:59

#include
#include
#include
using namespace std;
int main()
{
int a;
cin>>a;
string b[a];
for(int i=0;i<a;i++)
{
cin>>b[i];
sort(b[i].begin(),b[i].end());
do
{
for(int j=0;j<b[i].length();j++)
{
cout<<b[i][j];
}
cout<<endl;
}while(next_permutation(b[i].begin(),b[i].end()));
cout<<endl;
}

return 0;
}

WA (line:380236) python版

 

 

from sys import stdin, stdout
def gen_permuation(letters, start_index, current_str):
  if start_index >= len(letters):
    yield current_str
  else:
    unique_letters = set()
    for i in range(start_index, len(letters)):
      if not letters[i] in unique_letters:
        unique_letters.add(letters[i])
        if i != start_index:
          letters[start_index], letters[i] = letters[i], letters[start_index]
        yield from gen_permuation(letters, start_index + 1, current_str + letters[start_index])
        if i != start_index:
          letters[start_index], letters[i] = letters[i], letters[start_index]
def gen_permuation_sorted(letters, current_str):
  if len(letters) == 0:
    yield current_str
  else:
    unique_letters = set()
    for i in range(len(letters)):
      if not letters[i] in unique_letters:
        unique_letters.add(letters[i])
        yield from gen_permuation_sorted(letters[:i]+letters[i+1:], current_str + letters[i])
num_tests = int(input())
for i in range(num_tests):
  word = stdin.readline().strip()
  word = sorted(word)
  for word in gen_permuation_sorted(word, ""):
    stdout.write("{}\n".format(word))
  print()
 
ZeroJudge Forum