diff options
author | Jack Sangdahl <[email protected]> | 2024-12-17 13:29:21 -0700 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2024-12-17 13:29:21 -0700 |
commit | 3d1f61c860eed7b034d5673197cdc04b5555f8e5 (patch) | |
tree | 20208261d13e64a6ebfcc66fb4f8a6593bc8d675 | |
parent | be030b74805f245c8618c77b03e76f16b3fc945a (diff) | |
download | cses-3d1f61c860eed7b034d5673197cdc04b5555f8e5.tar.gz cses-3d1f61c860eed7b034d5673197cdc04b5555f8e5.zip |
1083. missing number
-rw-r--r-- | introductory_problems/missing_number.cpp | 15 | ||||
-rw-r--r-- | introductory_problems/readme.md | 7 |
2 files changed, 22 insertions, 0 deletions
diff --git a/introductory_problems/missing_number.cpp b/introductory_problems/missing_number.cpp new file mode 100644 index 0000000..7bb2dbd --- /dev/null +++ b/introductory_problems/missing_number.cpp @@ -0,0 +1,15 @@ +// 1083. Missing Number +#include <bits/stdc++.h> +using namespace std; + +int main() { + static int num, xum, x; + scanf("%d", &num); + for (int i = 1; i <= num; i++) + xum ^= i; + for (int i = 0; i < num - 1; i++) { + scanf("%d", &x); + xum ^= x; + } + printf("%d\n", xum); +} diff --git a/introductory_problems/readme.md b/introductory_problems/readme.md index 1ff88eb..d276f99 100644 --- a/introductory_problems/readme.md +++ b/introductory_problems/readme.md @@ -6,3 +6,10 @@ Consider an algorithm that takes as input a positive integer `n`. If `n` is even **Input**: The only input line contains an integer `n`. (Example: 3) **Output**: Print a line that contains all values of `n` during the algorithm. (Example: 3 10 5 16 8 4 2 1) + +### Missing Number +You are given all numbers between `1, 2, ..., n` except one. Your task is to find the missing number. + +**Input**: The first input line contains an integer `n`. The second input line contains `n - 1` numbers. Each number is distinct and between 1 and `n` (inclusive). (Example: 5`\n`2 3 1 5) + +**Output**: Print the missing number. (Example: 4) |