单词排序(不区分大小写,删除重复的单词)

#include 
#include "string.h"
#include 
#include "algorithm"

using namespace std;


bool math_my(string str1, string str2)
{
    int len1= str1.size();
    int len2 = str2.size();

    for(int i = 0; i < len1; ++i)
    {
        if((str1[i] >= 'A') && (str1[i] <= 'Z'))
        {
            str1[i] = str1[i] + 32;
        }
    }

    for(int i = 0; i < len2; ++i)
    {
        if((str2[i] >= 'A') && (str2[i] <= 'Z'))
        {
            str2[i] = str2[i] + 32;
        }
    }


    cout<<"str1="< result;
    vector dp;

    memset(str, 0, sizeof(str));

    while(gets(str))
    {

        string tmp;


        int len = strlen(str);
        char str_tmp[256];
        int i = 0;
        int j = 0;
        int flag = 0;

        memset(str_tmp, 0, sizeof(str_tmp));

        memcpy(str_tmp, str, len);


        for(i = 0; i < len; ++i)
        {
            if(' ' != str[i])
            {
                tmp += str[i];
            }
            else
            {

                for(j = result.size()-1; j >= 0 ; j--)
                {

                    flag = 0;
                    if(math_my(result[j],tmp))
                    {
                        flag = 1;
                        break;

                    }

                }

                if(flag == 0)
                {
                    result.push_back(tmp);
                }
                tmp.clear();
            }
        }


        if(0 != tmp.size())
        {
            result.push_back(tmp);
            tmp.clear();
        }



        sort(result.begin(),result.end());
        result.erase(unique(result.begin(),result.end()), result.end());


/*
        //输出时判断也可以
        for(int i = 1; i< result.size(); ++i)
        {
            for(j = i - 1; j >= 0; j--)
            {
                if(math_my(result[i],result[j]))
                {
                   result.erase(result.begin()+i);
                }

            }

        }
*/
         for(int i = 0; i< result.size(); ++i)
         {
            cout<

 

你可能感兴趣的:(单词排序(不区分大小写,删除重复的单词))