📄 words_assort.cpp
字号:
/*
* Description:
*
* Assort words.
*
* History:
*
* Initial version created by Royal, Mar. 2004.
*
* Notes:
*
* This code has been written to conform to standard C++ and STL. It has been
* compiled successfully using GNU C++ 3.2, Borland C++ 5.5, and Visual C++ 7.0.
*/
#include<iostream>
#include<string>
#include<vector>
using namespace std;
void output(const vector<string>& words);
void assort(string word, vector<string>& lower_words, vector<string>& upper_words, vector<string>& other_words);
int main()
{
string word;
vector<string>lowers, uppers, others;
cout << "Please input a series of words:" << endl;
while(cin >> word) assort(word, lowers, uppers, others);
cout << " The words in lowercase:" << endl;
output(lowers);
cout << "The words in uppercase:" << endl;
output(uppers);
cout << "others:" << endl;
output(others);
}
void assort(string word, vector<string>& lower_words, vector<string>& upper_words, vector<string>& other_words)
{
char* initial = &word[0];
if (islower(*initial))
{
while(islower(*initial))
{
initial++;
if(*initial == '\0') lower_words.push_back(word);
}
if(*initial != '\0') other_words.push_back(word);
}
else if(isupper(*initial))
{
while(isupper(*initial))
{
initial++;
if(*initial == '\0') upper_words.push_back(word);
}
if(*initial != '\0') other_words.push_back(word);
}
else other_words.push_back(word);
}
void output(const vector<string>& words)
{
vector<string>::const_iterator it = words.begin();
vector<string>::const_iterator end_it = words.end();
while (it != end_it)
{
cout << *it << "\t";
++it;
}
cout << endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -