我是虫的主人 2019-02-27 13:10 采纳率: 0%
浏览 229

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;

}

  • 写回答

1条回答 默认 最新

  • moun_tain 2020-08-01 20:46
    关注

    我这个超时了

    #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;
    }
    
    
    评论

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法