summaryrefslogtreecommitdiff
path: root/acwing/1224.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-03-10 08:54:21 +0800
committercrupest <crupest@outlook.com>2021-03-10 08:54:21 +0800
commit47db56ec496a18b98d73d8694e4836cd8eca40af (patch)
tree0b4d303cca8d7da18caf75ccc489773ca067c845 /acwing/1224.cpp
parent19019d08a46c953060dc6744552d76d0099a589a (diff)
downloadsolutions-47db56ec496a18b98d73d8694e4836cd8eca40af.tar.gz
solutions-47db56ec496a18b98d73d8694e4836cd8eca40af.tar.bz2
solutions-47db56ec496a18b98d73d8694e4836cd8eca40af.zip
Add acwing 1224.
Diffstat (limited to 'acwing/1224.cpp')
-rw-r--r--acwing/1224.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/acwing/1224.cpp b/acwing/1224.cpp
new file mode 100644
index 0000000..8cdd9f0
--- /dev/null
+++ b/acwing/1224.cpp
@@ -0,0 +1,33 @@
+#include <iostream>
+#include <utility>
+
+int N;
+int x[10010];
+
+int main() {
+ std::ios_base::sync_with_stdio(false);
+ std::cin.tie(nullptr);
+
+ std::cin >> N;
+ for (int i = 1; i <= N; i++) {
+ std::cin >> x[i];
+ }
+
+ int result = 0;
+
+ for (int i = 1; i <= N - 1; i++) {
+ if (x[i] != i) {
+ for (int j = i + 1; j <= N; j++) {
+ if (x[j] == i) {
+ x[j] = x[i];
+ result++;
+ break;
+ }
+ }
+ }
+ }
+
+ std::cout << result;
+
+ return 0;
+}