C/C++の宿題を片付けます 97代目
■ このスレッドは過去ログ倉庫に格納されています
0409デフォルトの名無しさん
2007/10/16(火) 16:57:05#include <iostream>
#include <string>
#include <functional>
#include <algorithm>
using namespace std;
int upper_num;
int lower_num;
int digit_num;
struct Counter : unary_function<char, void> {
void operator () (char c) {
if ('A' <= c && 'Z' >= c)
++upper_num;
else if ('a' <= c && 'z' >= c)
++lower_num;
else if ('0' <= c && '9' >= c)
++digit_num;
}
};
int main() {
string str;
cin >> str;
for_each(str.begin(), str.end(), Counter());
cout << "upper: " << upper_num << endl;
cout << "lower: " << lower_num << endl;
cout << "digit: " << digit_num << endl;
}
■ このスレッドは過去ログ倉庫に格納されています