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
commitddce387d48c6b4c1ab7c87659f8d1c2946ab5bde (patch)
treec74a8762070c5c4f1626d97ea139092fe69d5a19
parente0abdf25655c78298937e8a530d56c3e32e804ae (diff)
downloadcrupest-ddce387d48c6b4c1ab7c87659f8d1c2946ab5bde.tar.gz
crupest-ddce387d48c6b4c1ab7c87659f8d1c2946ab5bde.tar.bz2
crupest-ddce387d48c6b4c1ab7c87659f8d1c2946ab5bde.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;
+}