aboutsummaryrefslogtreecommitdiff
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
commitc4975c854cb5365872c4c9707deb659e0d2634eb (patch)
treebbde795100c8708634800dcff0377969d8cb8b75
parentfdff564b14ea72719852a38e9eca7d61f2cf01af (diff)
downloadcrupest-c4975c854cb5365872c4c9707deb659e0d2634eb.tar.gz
crupest-c4975c854cb5365872c4c9707deb659e0d2634eb.tar.bz2
crupest-c4975c854cb5365872c4c9707deb659e0d2634eb.zip
import(solutions): Add acwing 1224.
-rw-r--r--works/solutions/acwing/1224.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/works/solutions/acwing/1224.cpp b/works/solutions/acwing/1224.cpp
new file mode 100644
index 0000000..8cdd9f0
--- /dev/null
+++ b/works/solutions/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;
+}