-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
381e017
commit 2c83d27
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} | ||
} | ||
``` |