io20_2_1.04.c
来自「C++ Primer(第三版)的随书源代码」· C语言 代码 · 共 43 行
C
43 行
// #include <iostream>
#include <iostream.h>
#include <string>
/**
**
stanl@john: d.ch20 261 : a.out < alice_emma
The number of words read is 65
The longest word has a length of 10
The longest word is creature,"
**
**/
int main()
{
string buf, largest;
// hold statistics;
int curLen, // length of current word
max = -1, // maximum word length
cnt = 0; // count of words read
while ( cin >> buf )
{
curLen = buf.size();
++cnt;
// new longest word? save it.
if ( curLen > max )
{
max = curLen;
largest = buf;
}
}
cout << "The number of words read is " << cnt << endl;
cout << "The longest word has a length of " << max << endl;
cout << "The longest word is " << largest << endl;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?