c++小题目2

c++小题目

题目:编写程序,将一个英文句子中的单词进行分离并存入一维指针中,然后按词典顺序输出这些单词。

/**************************作者:李云***************************/
/************************时间:2017、9、8***********************/
/**************题目:将句子中的单词分离并输出*******************/

#include<iostream>
#include<string>
using namespace std;

class ZIFU
{
    friend void yasuo(ZIFU &Sentence);
private:
    char *sen;
public:
    ZIFU(char *des){ sen = des;}
};
void yasuo(ZIFU &SenTence)
{
    int flag = false;
    for (int i = 0; SenTence.sen[i]; i++)
    {
        if (SenTence.sen[i] != ' ')
        {
            cout << SenTence.sen[i];
            flag = true;
        }
        else
        {
            if (flag)
            {
                cout << endl;
                flag = false;
            }
            else continue;
        }
    }
}
int main()
{  
    char *m = "sdf asdf vds   sdfa";
    ZIFU s(m);
    yasuo(s);
    cout << endl;
}

猜你喜欢

转载自blog.csdn.net/qq_36327328/article/details/77900566