ランダムな文字列を入力として受け取るアルゴリズムを書いています。発生した最大長と、その特定の長さの単語数を出力する必要があります。はい、別のアプローチを使用できることはわかっていますが、各文字列を av[it's length] に格納することを考えていました。同じ長さの文字列が複数ある場合は、u[same length] をインクリメントしてから、それらの値を出力します。v[length] がすでに設定されているかどうかを確認するにはどうすればよいですか?
悪い英語で申し訳ありません。
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef unsigned short us;
typedef vector<string> vstr;
typedef vector<us> vus;
int main()
{
string str;
vstr v;
vus u(50, 1);
us len;
while (cin >> str && str != "0")
{
len = str.length();
//if there is an element set at v[len] then ++u[len] otherwise v[len] = str;
}
//bunch of other code
return 0;
}