- 笨笨的单词排序
- 2017-01-31 20:54:08 @
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iomanip>
using namespace std;
int main() {
//freopen("//xx.in","r",stdin);
//freopen("//xx.out","w",stdout);
string a;
cin>>a;
int n;
char p;
string word[1001];
cin>>n;
for (int i=1;i<=n;i++) cin>>word[i];
cin>>p;
if (p=='1')
{
int n1=0,n2=0;
for (int i=1;i<=n;i++)
{
for (int j=i+1;j<=n;j++)
{
int x=min(word[i].size(),word[j].size());
for (int k=0;k<=25;k++)
{
for (int l=0;l<=x-1;l++)
{
if (word[i][l]==a[k]) n1=k;
if (word[j][l]==a[k]) n2=k;
if (n1<n2) swap (word[i],word[j]);continue;
}
}
}
}
}
else
{
int n3=0,n4=0;
for (int i=1;i<=n;i++)
{
for (int j=i+1;j<=n;j++)
{
int y=min(word[i].size(),word[j].size());
for (int k=0;k<=25;k++)
{
for (int l=0;l<=y-1;l++)
{
if (word[i][l]==a[k]) n3=k;
if (word[j][l]==a[k]) n4=k;
if (n3<n4) swap (word[i],word[j]);continue;
}
}
}
}
}
for (int i=1;i<=n;i++) cout<<word[i]<<endl;
//fclose(stdin);
//fclose(stdout);
//while (1);
return 0;
}
TLE+WA