UVa 156反片语,帮忙看一下代码哪里

#include
#include
#include
#include
#include
#include
using namespace std;
string s,sr;
vectors1;
vectorst;
string stand_string(string s){
string ans;
for (int i = 0; i < s.length(); i++) {
if (isalpha(s[i]))
ans[i] = tolower(s[i]);
}
sort(ans.begin(), ans.end());
return ans;
}
int main() {

while (cin >> s) {
    stringstream ss(s);
    while (ss >> sr && sr != "#")s1.push_back(sr);
}
vector<string>::iterator it,it1;
for (it = s1.begin(); it != s1.end(); it++)
    st.push_back(stand_string(*it));
for (it = st.begin(); it != st.end(); it++) {
    int flag = 1;
    for (it1= st.begin() + 1; it1!= st.end(); it1++) 
        if (*it == *it1)flag = 0;
    if (*it == "#")break;
    if (flag)cout << *it << '\n';
}
return 0;

}

我这个超时了

#include<bits/stdc++.h>
using namespace std;
struct str{
    char s[1001];
    char a_s[1001];
    char sort_s[1001];
    bool chong=0;
}a[10001];
int main()
{
    int n=1;
    while(cin>>a[n].s)
    {
        if(strcmp(a[n].s,"#")==0)
        break;
        int l=strlen(a[n].s);
        strcpy(a[n].sort_s ,a[n].s);
        strcpy(a[n].a_s ,a[n].s);
        for(int j=0;j<=l-1;j++)
        {
            a[n].a_s[j]=tolower(a[n].a_s[j]);
            a[n].sort_s[j]=tolower(a[n].sort_s[j]);
        }
        sort(a[n].sort_s,a[n].sort_s+l);
        n++;
    }
    n--;
    for(int i=1;i<=n-1;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            if(strcmp(a[i].sort_s,a[j].sort_s)>=0)
            {
                str tmp;
                tmp=a[i];
                a[i]=a[j];
                a[j]=tmp;
            }
        }
    }
    bool f=0;
    for(int i=1;i<=n;i++)
    if(strcmp(a[i].sort_s,a[i+1].sort_s)==0)
    {
        a[i].chong=1;
        a[i+1].chong=1;
    }
    for(int i=1;i<=n-1;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            if(strcmp(a[i].s,a[j].s)>=0)
            {
                str tmp;
                tmp=a[i];
                a[i]=a[j];
                a[j]=tmp;
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i].chong==0)
        {
            cout<<a[i].s<<'\n';
        }
    }
    return 0;
}