program_4_8.cpp
来自「清华关于C++ 的程序讲义 值得一看 关于算法」· C++ 代码 · 共 29 行
CPP
29 行
// Program 4.8: Computes number of words and articles
#include <iostream>
#include <string>
using namespace std;
int main() {
// initialize counters ofr test analysis
int NumberOfWords = 0;
int NumberOfArticles = 0;
// begin string processing
string s;
cout << "Enter text for analysis" << endl << endl;
while (cin >> s) {
// found another word
++NumberOfWords;
// test if the word an article
if ((s == "the") || (s == "The") || (s == "an")
|| (s == "An") || (s == "a") || (s == "A")) {
// the word an article
++NumberOfArticles;
}
}
// display test statistics
cout << endl;
cout << "Text contains " << NumberOfWords
<< " Words of which " << NumberOfArticles
<< " are articles" << endl;
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?