c++(.cpp)
请给我这个程序的代码并写明注释
1、开始时提示你输入若干行字符串(char)
2、你输入后程序将每一行都存储在a[0],a[1],[2]......
3、最后输出你输了几行,最长的一行有几个字符
参考答案:C++的话简单:
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstddef>
using namespace std;
bool bigger_size(string &small, string &big)
{
return small.size() < big.size();
}
int main()
{
string str;
vector<string> vstr;
typedef vector<string>::iterator ite;
cout << "Please enter arbitrary lines of literals" << endl;
cout << "You can press Ctrl + Z simultaneously to stop:" << endl;
size_t line = 1;
cout << "line " << line << ": ";
while(getline(cin, str))
{
vstr.push_back(str);
++line;
cout << "line " << line << ": ";
}
ite it;
size_t max_size = (it = max_element(vstr.begin(), vstr.end(), bigger_size))->size();
cout << "You've totally entered "<< vstr.size() << " lines of literals." << endl;
cout << "And literal: " << *it << endl << "has the biggest size of " << max_size;
}