UVa156

自己的代码神他妈繁琐,还是刘汝佳伟大

#pragma warning(disable:4996)
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iostream>
#include<time.h>
#include<set>
#include<sstream>
#include<functional>
#include<cassert>
#include<list>
#include<iterator>
#include<utility>
#include <stdexcept>
#include <sstream>
#include <fstream>
#include<ctype.h>
#include<map>
#include<stack>
#include<queue>
#include<cstdlib>

using namespace std;

string word[1500];
char wordtmp[1500];
string wordtemp[1500];
map<string,int> s;
string change(const string& str)
{
    string ans = str;
    sort(ans.begin(), ans.end());
    return ans;
}

int main()
{
    string str;
    while (getline(cin, str, '#'))
    {
        int k = 0;
        auto len = str.length();
        stringstream ss1(str);
        string temp1;
        while (ss1 >> temp1)
        {
            wordtemp[k++] = temp1;
        }
        for (auto iter = str.begin();iter != str.end();iter++)
        {
            if (isalpha(*iter))
                *iter = tolower(*iter);
        }
        k = 0;
        stringstream ss2(str);
        string temp2;
        while (ss2 >> temp2)
        {
            word[k++] = temp2;
        }
        for (int i = 0;i < k;i++)
        {
            word[i]=change(word[i]);
        }
        vector<int> vs;
        for (int i = 0;i < k;i++)
        {
            for (int j = i + 1;j < k;j++)
            {
                if (word[i] == word[j])
                {
                    vs.push_back(i);
                    vs.push_back(j);
                }
            }
        }
        for (auto iter = vs.begin();iter != vs.end();iter++)
        {
            word[*iter] = "";
        }
        vector<string> vc;
        for(int i=0;i<k;i++)
        {
            if (word[i] != "")
                vc.push_back(wordtemp[i]);
        }
        sort(vc.begin(), vc.end());
        for (auto iter = vc.begin();iter != vc.end();iter++)
            cout << *iter << endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/jack_jyh/article/details/53358704
今日推荐