关于输入

// cin >> noskipws;
char ch[20];
string str;

// cin.get(ch ,2);
/*getline(cin,str);*/
cin.getline(ch,5);
cout << ch<<endl;

// cout << str;

统计单词个数等信息 用时要测试

typedef map<string, int> count_map;
typedef count_map::iterator count_iter;
typedef string::size_type str_size;


count_map counts;
string word;
string okay("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghigklmnopqrstuvwxyz"
"1234567890-_");
while (cin>>word)
{
string copy;
for (string::iterator w(word.begin()); w != word.end(); ++w)
{
if (okay.find(*w) != string::npos)
copy.push_back(*w);
}
if (!copy.empty())
++counts[copy];


}
str_size longest(0);
for (count_iter iter(counts.begin()); iter != counts.end();++iter)
{
if (iter->first.size() > longest)
longest = iter->first.size();
}
const int count_size(10);
for (count_iter iter(counts.begin()); iter!=counts.end(); ++iter)
{
cout << setw(longest) << left << iter->first << 
setw(count_size) << right << iter->second << endl;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值