c++大小写计数

来源:百度知道 编辑:UC知道 时间:2024/06/30 11:19:33
题意描述:编写一个程序来输出在输入中的单词,输出的格式是:先输出全部的小写单词,然后输出首字母大写的单词,最后输出大写单词。(假设只有这三种形式的单词)
我的程序如下 希望大家指点 谢谢各位大侠了
#include <iostream>
#include <string>
#include <vector>

using std::cin; using std::cout;
using std::streamsize; using std::string;
using std::endl; using std::vector;

int main()
{ cout<<"please enter your words:";
vector<string> words;
string x;
while(cin>>x)
{ words.push_back(x);
int size=words.size();}
int zimu(int i,int j)
{if(words[i][j]>='a'&&words[i][j]<='z')
{
cout<<"the small words is:"<<words[i]<<endl;
}
else if (words[i][j]>='A'&&words[i][j]<='Z');
{
cout<<"the big words is:"<<words[i]<<endl;
}}

for(int i=0;i<words.size();++i)
{

建议用sort函数 自己写个 cmp
int getkind( string a)
{
if( a[0] >='a' && a[0] <= 'z')
return 0; //小写
int len = a.size();
if( a[len-1] >='a' && a[len-1] <= 'z')
return 1; // 只有首字母大写
return 2; // 全大写
}
bool cmp( string a, string b)
{
int an = getkind(a);
int bn = getkind(b);
if(an <bn) // 字母不一样的类型
return true;
//类型一样,按照ascii排序
return a< b;
}
main()
{

sort( words.begin(), word.end(),cmp);
}