Skip to content

Commit

Permalink
Update 027.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Reputeless committed Dec 16, 2021
1 parent 381e017 commit 2c83d27
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions 027.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
# 027 - Sign Up Requests (★2)

`std::unordered_set::insert()` は戻り値として `std:pair<iterator, bool>` を返します。この `.second` 部 (`bool`) は、コンテナへのキーの追加に成功した(コンテナに同じキーが存在しなかった)場合に `true`, 追加に失敗した(コンテナに同じキーが既に存在した)場合に `false` を返します。

```cpp
#include <iostream>
#include <string>
#include <unordered_set>

int main()
{
// N 日間にわたる申請
int N;
std::cin >> N;

// 登録済みのユーザ名を記録するハッシュテーブル
std::unordered_set<std::string> ids;

for (int i = 1; i <= N; ++i) // i 日目
{
// 申請されたユーザ名
std::string id;
std::cin >> id;

if (ids.insert(id).second) // ユーザ名を新規登録できた場合
{
// 日にちを出力
std::cout << i << '\n';
}
}
}
```

0 comments on commit 2c83d27

Please sign in to comment.