commit 3d1f61c860eed7b034d5673197cdc04b5555f8e5
parent be030b74805f245c8618c77b03e76f16b3fc945a
Author: Jack Sangdahl <jack@pngu.org>
Date: Tue, 17 Dec 2024 13:29:21 -0700
1083. missing number
Diffstat:
2 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/introductory_problems/missing_number.cpp 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
@@ -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)