文字列分類、出力文字列のアルファベット、数値、記号の個数

1665 ワード

/*  
* Copyright (c) 2012,            
* All rights reserved.  
*       :      
*     :2012   11   17    
*      :v1.0  
*  
*     :                     
*     :                         
*     :                         
*     : 
*     :  
*/  

# include 
# include //  string  
# include //string         

using namespace std;

/*    */
int alphabet(string);   //      
int number(string);     //       
int punctuation(string);//        

int main()
{
	/*     */
	string str1;
	int ialphabet = 0;
	int inumber = 0;
	int ipunctuation = 0;

	/*     */
	cout << "please input strings:";
	cin  >> str1;

	/*        */
	ialphabet = alphabet(str1);
	inumber = number(str1);
	ipunctuation = punctuation(str1);

	/*  */
	cout << ialphabet
		 << " of alphabets,"
		 << inumber
		 << " of numbers,"
		 << ipunctuation
		 << " of punctuations.
"; return 0;//main } int alphabet(string str)/* */ { int num = 0; for (string::size_type count = 0; count != str.size(); ++count) { if (isalpha(str[count]))//isalpha() : , true, false { ++num; } } return num; } int number(string str) { int num = 0; for (string::size_type count = 0; count != str.size(); ++count) { if (isdigit(str[count]))//isdigit() : , true, false { ++num; } } return num; } int punctuation(string str) { int num = 0; for (string::size_type count = 0; count != str.size(); ++count) { if (ispunct(str[count]))//ispunct() : , true, false { ++num; } } return num; }