tangs преди 7 години
родител
ревизия
ba0efe01de
променени са 8 файла, в които са добавени 157 реда и са изтрити 0 реда
  1. 7 0
      section2-6/CMakeLists.txt
  2. 20 0
      section2-6/main.cpp
  3. 7 0
      section2-7/CMakeLists.txt
  4. 66 0
      section2-7/main.cpp
  5. 7 0
      section2-7解法2/CMakeLists.txt
  6. 21 0
      section2-7解法2/main.cpp
  7. 7 0
      section2-8/CMakeLists.txt
  8. 22 0
      section2-8/main.cpp

+ 7 - 0
section2-6/CMakeLists.txt

@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 3.6)
+project(section2_6)
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+
+set(SOURCE_FILES main.cpp)
+add_executable(section2_6 ${SOURCE_FILES})

+ 20 - 0
section2-6/main.cpp

@@ -0,0 +1,20 @@
+#include <iostream>
+
+using namespace std;
+
+int main() {
+    int T;
+    bool line = false;
+    while (cin >> T) {
+        if (line) {
+            line = true;
+            cout << endl;
+        }
+        for (int i = 0; i < T; i++) {
+            int intKey = 0;
+            cin >> intKey;
+            cout << char(intKey);
+        }
+    }
+    return 0;
+}

+ 7 - 0
section2-7/CMakeLists.txt

@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 3.6)
+project(section2_7)
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+
+set(SOURCE_FILES main.cpp)
+add_executable(section2_7 ${SOURCE_FILES})

+ 66 - 0
section2-7/main.cpp

@@ -0,0 +1,66 @@
+#include <iostream>
+
+using namespace std;
+
+int calc(char *num) {
+    int result = 0;
+    for (int i = 0; num[i] != '\0'; i++) {
+        if (num[i] >= '0' && num[i] <= '9') {
+            result += num[i] - '0';
+        } else if (num[i] >= 'A' && num[i] <= 'F') {
+            result += num[i] - 'A' + 10;
+        }
+    }
+    return result;
+}
+
+int duodecimal(int i) {
+    char ch[20] = {'\0'};
+    int result = 0;
+    int count = 0, base = 12;
+    for (; i != 0;) {
+        int s = i % base;
+        result += s;
+        if (s >= 10) {
+            ch[count] = 'A' + (s - 10);
+
+        } else {
+            ch[count] = '0' + s;
+        }
+        count++;
+        i /= base;
+    }
+//    cout << ch << " - " << i << endl;
+    return result;
+}
+
+int main() {
+    char *charA = new char[12], *charB = new char[12];
+    memset(charA, 0, 12);
+    memset(charB, 0, 12);
+    int numA = 0, numB = 0, numC = 0;
+    for (int i = 1000; i <= 9999; i++) {
+        sprintf(charA, "%X", i);
+        sprintf(charB, "%d", i);
+
+        numA = calc(charA);
+        numB = calc(charB);
+
+//        cout << charA << " - " << numA << " - " << charB << " - " << numB << endl;
+
+        memset(charA, 0, 12);
+        memset(charB, 0, 12);
+
+        if (numA != numB) {
+            continue;
+        }
+        numC = duodecimal(i);
+        if (numA != numC) {
+            continue;
+        }
+        cout << i << endl;
+    }
+
+    free(charA);
+    free(charB);
+}

+ 7 - 0
section2-7解法2/CMakeLists.txt

@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 3.6)
+project(section2_72)
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+
+set(SOURCE_FILES main.cpp)
+add_executable(section2_72 ${SOURCE_FILES})

+ 21 - 0
section2-7解法2/main.cpp

@@ -0,0 +1,21 @@
+#include <iostream>
+
+using namespace std;
+
+int trans(int i, int base) {
+    int result = 0;
+    for (; i;) {
+        result += i % base;
+        i /= base;
+    }
+    return result;
+}
+
+int main() {
+    for (int i = 2992; i <= 9999; i++) {
+        if (trans(i, 10) == trans(i, 12) && trans(i, 10) == trans(i, 16)) {
+            cout << i << endl;
+        }
+    }
+    return 0;
+}

+ 7 - 0
section2-8/CMakeLists.txt

@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 3.6)
+project(section2_8)
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+
+set(SOURCE_FILES main.cpp)
+add_executable(section2_8 ${SOURCE_FILES})

+ 22 - 0
section2-8/main.cpp

@@ -0,0 +1,22 @@
+#include <iostream>
+#include <string>
+
+using namespace std;
+
+int main() {
+
+    string input;
+    int index = 0;
+    while (getline(cin, input)) {
+        int record[26] = {0};
+        for (int i = 0; i < input.length(); i++) {
+            index = input[i] - 'a';
+            record[index]++;
+        }
+        for (int i = 0; i < 26; i++) {
+            cout << (char) ('a' + i) << ":" << record[i] << endl;
+        }
+        cout << endl;
+    }
+    return 0;
+}