소스 검색

//问题 F神奇的数字 枚举优化(枚举一半)

zj 5 년 전
부모
커밋
2e29e380a9
1개의 변경된 파일32개의 추가작업 그리고 0개의 파일을 삭제
  1. 32 0
      F.cpp

+ 32 - 0
F.cpp

@@ -0,0 +1,32 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+//问题 F神奇的数字 枚举优化(枚举一半)
+const int T[] = {0,1, 10, 100, 1000, 10000, 100000, 1000000};
+
+int main() {
+    int n;
+    cin >> n;
+    char s[100];
+    if (n & 1) {
+        int a = n / 2 + 1;
+        for (int i = T[a]; i < T[a + 1]; i++) {
+            sprintf(s,"%d",i);
+            cout<<s;
+            s[strlen(s)-1]=0;
+            reverse(s,s+strlen(s));
+            cout<<s<<endl;
+        }
+    }else{
+        int a = n / 2 ;
+        for (int i = T[a]; i < T[a + 1]; i++) {
+            sprintf(s,"%d",i);
+            cout<<s;
+            reverse(s,s+strlen(s));
+            cout<<s<<endl;
+        }
+    }
+
+    return 0;
+}