From 033c694022e04b3d20c45e52c7489875a36e5dc5 Mon Sep 17 00:00:00 2001 From: liuchuo <95323362@qq.com> Date: Thu, 6 Sep 2018 01:47:53 +0800 Subject: [PATCH] :art: style: improve format of the code --- AdvancedLevel_C++/1070. Mooncake (25).cpp | 9 +-- .../1110. Complete Binary Tree (25).cpp | 76 ++++++++----------- ...5\215\260\346\262\231\346\274\217(20).cpp" | 18 ++--- ...0\272\253\344\273\275\350\257\201(15).cpp" | 13 +--- ...\345\215\260\346\262\231\346\274\217 .cpp" | 37 +++------ ...\346\225\260\347\273\237\350\256\241 .cpp" | 8 +- ...\345\272\247\344\275\215\345\217\267 .cpp" | 18 ++--- ...6\347\273\255\345\233\240\345\255\220.cpp" | 30 -------- ...4\346\225\260\346\256\265\345\222\214.cpp" | 3 +- ...4\350\276\203\345\244\247\345\260\217.cpp" | 12 +-- CCCC-GPLT/L1-011. A-B.cpp | 8 +- ...7\351\230\266\344\271\230\345\222\214.cpp" | 7 +- ...4\350\272\253\344\273\275\350\257\201.cpp" | 28 +++---- ...5\346\234\211\345\244\232\344\272\214.cpp" | 12 +-- ...5\350\257\264\344\270\211\351\201\215.cpp" | 2 +- ...7\345\201\266\345\210\206\345\256\266.cpp" | 3 +- ...46\255\243\346\225\264\346\225\260A+B.cpp" | 20 ++--- ...4\346\226\255\347\264\240\346\225\260.cpp" | 15 ++-- ... \344\270\200\345\270\256\344\270\200.cpp" | 8 +- ... \346\203\205\344\272\272\350\212\202.cpp" | 4 +- ...3\350\272\253\351\253\230\345\267\256.cpp" | 16 ---- .../L1-041 \345\257\273\346\211\276250.cpp" | 3 +- .../L1-044 \347\250\263\350\265\242.cpp" | 21 +++++ ...4\345\244\247\346\213\233\345\221\274.cpp" | 8 ++ ...4\351\231\244\345\205\211\346\243\215.cpp" | 19 +++++ .../L1-047 \350\243\205\347\235\241.cpp" | 13 ++++ ...351\230\265A\344\271\230\344\273\245B.cpp" | 34 +++++++++ ...7\344\275\215\345\210\206\351\205\215.cpp" | 38 ++++++++++ ...2\345\255\227\347\254\246\344\270\262.cpp" | 19 +++++ .../L1-051 \346\211\223\346\212\230.cpp" | 7 ++ ...1\344\273\254\350\246\201\350\265\242.cpp" | 5 ++ ... \347\224\265\345\255\220\346\261\252.cpp" | 8 ++ ... \347\246\217\345\210\260\344\272\206.cpp" | 28 +++++++ ...1\346\230\257\350\265\242\345\256\266.cpp" | 12 +++ ... \347\214\234\346\225\260\345\255\227.cpp" | 21 +++++ ...2\346\240\221\345\220\227\357\274\237.cpp" | 3 +- ...0\347\233\270\344\274\274\345\272\246.cpp" | 5 +- 37 files changed, 338 insertions(+), 253 deletions(-) delete mode 100644 "CCCC-GPLT/L1-040 \346\234\200\344\275\263\346\203\205\344\276\243\350\272\253\351\253\230\345\267\256.cpp" create mode 100644 "CCCC-GPLT/L1-044 \347\250\263\350\265\242.cpp" create mode 100644 "CCCC-GPLT/L1-045 \345\256\207\345\256\231\346\227\240\346\225\214\345\244\247\346\213\233\345\221\274.cpp" create mode 100644 "CCCC-GPLT/L1-046 \346\225\264\351\231\244\345\205\211\346\243\215.cpp" create mode 100644 "CCCC-GPLT/L1-047 \350\243\205\347\235\241.cpp" create mode 100644 "CCCC-GPLT/L1-048 \347\237\251\351\230\265A\344\271\230\344\273\245B.cpp" create mode 100644 "CCCC-GPLT/L1-049 \345\244\251\346\242\257\350\265\233\345\272\247\344\275\215\345\210\206\351\205\215.cpp" create mode 100644 "CCCC-GPLT/L1-050 \345\200\222\346\225\260\347\254\254N\344\270\252\345\255\227\347\254\246\344\270\262.cpp" create mode 100644 "CCCC-GPLT/L1-051 \346\211\223\346\212\230.cpp" create mode 100644 "CCCC-GPLT/L1-052 2018\346\210\221\344\273\254\350\246\201\350\265\242.cpp" create mode 100644 "CCCC-GPLT/L1-053 \347\224\265\345\255\220\346\261\252.cpp" create mode 100644 "CCCC-GPLT/L1-054 \347\246\217\345\210\260\344\272\206.cpp" create mode 100644 "CCCC-GPLT/L1-055 \350\260\201\346\230\257\350\265\242\345\256\266.cpp" create mode 100644 "CCCC-GPLT/L1-056 \347\214\234\346\225\260\345\255\227.cpp" diff --git a/AdvancedLevel_C++/1070. Mooncake (25).cpp b/AdvancedLevel_C++/1070. Mooncake (25).cpp index 9933ac3..79bc013 100644 --- a/AdvancedLevel_C++/1070. Mooncake (25).cpp +++ b/AdvancedLevel_C++/1070. Mooncake (25).cpp @@ -12,12 +12,9 @@ int main() { int n, need; cin >> n >> need; vector a(n); - for (int i = 0; i < n; i++) - cin >> a[i].mount; - for (int i = 0; i < n; i++) - cin >> a[i].price; - for (int i = 0; i < n; i++) - a[i].unit = a[i].price / a[i].mount; + for (int i = 0; i < n; i++) scanf("%f", &a[i].mount); + for (int i = 0; i < n; i++) scanf("%f", &a[i].price); + for (int i = 0; i < n; i++) a[i].unit = a[i].price / a[i].mount; sort(a.begin(), a.end(), cmp); float result = 0.0; for (int i = 0; i < n; i++) { diff --git a/AdvancedLevel_C++/1110. Complete Binary Tree (25).cpp b/AdvancedLevel_C++/1110. Complete Binary Tree (25).cpp index 73e5167..1097606 100644 --- a/AdvancedLevel_C++/1110. Complete Binary Tree (25).cpp +++ b/AdvancedLevel_C++/1110. Complete Binary Tree (25).cpp @@ -1,56 +1,42 @@ #include -#include -#include -#include using namespace std; -struct TREE { - int left, right; -}; +struct node{ + int l, r; +}a[100]; +int maxn = -1, ans; +void dfs(int root, int index) { + if(index > maxn) { + maxn = index; + ans = root; + } + if(a[root].l != -1) dfs(a[root].l, index * 2); + if(a[root].r != -1) dfs(a[root].r, index * 2 + 1); +} int main() { - int n, root = 0; - scanf("%d", &n); - vector tree(n); - vector book(n); - for(int i = 0; i < n; i++) { + int n, root = 0, have[100] = {0}; + cin >> n; + for (int i = 0; i < n; i++) { string l, r; cin >> l >> r; - if(l == "-") { - tree[i].left = -1; + if (l == "-") { + a[i].l = -1; } else { - tree[i].left = stoi(l); - book[tree[i].left] = 1; + a[i].l = stoi(l); + have[stoi(l)] = 1; } - if(r == "-"){ - tree[i].right = -1; + if (r == "-") { + a[i].r = -1; } else { - tree[i].right = stoi(r); - book[tree[i].right] = 1; - } - } - for(int i = 0; i < n; i++) { - if(book[i] == 0) { - root = i; - break; - } - } - queue q; - q.push(root); - int cnt = 0, lastnode = 0; - while(!q.empty()) { - int node = q.front(); - q.pop(); - if(node != -1) { - lastnode = node; - cnt++; - }else { - if(cnt != n) - printf("NO %d", root); - else - printf("YES %d", lastnode); - return 0; + a[i].r = stoi(r); + have[stoi(r)] = 1; } - q.push(tree[node].left); - q.push(tree[node].right); } + while (have[root] != 0) root++; + dfs(root, 1); + if (maxn == n) + cout << "YES " << ans; + else + cout << "NO " << root; return 0; -} \ No newline at end of file +} + diff --git "a/BasicLevel_C++/1027. \346\211\223\345\215\260\346\262\231\346\274\217(20).cpp" "b/BasicLevel_C++/1027. \346\211\223\345\215\260\346\262\231\346\274\217(20).cpp" index 8d5f102..72e0ff3 100644 --- "a/BasicLevel_C++/1027. \346\211\223\345\215\260\346\262\231\346\274\217(20).cpp" +++ "b/BasicLevel_C++/1027. \346\211\223\345\215\260\346\262\231\346\274\217(20).cpp" @@ -1,10 +1,9 @@ #include using namespace std; int main() { - int N; + int N, row = 0; char c; cin >> N >> c; - int row = 0; for (int i = 0; i < N; i++) { if ((2 * i * (i + 2) + 1) > N) { row = i - 1; @@ -12,20 +11,15 @@ int main() { } } for (int i = row; i >= 1; i--) { - for (int k = row - i; k >= 1; k--) - cout << " "; - for (int j = i * 2 + 1; j >= 1; j--) - cout << c; + for (int k = row - i; k >= 1; k--) cout << " "; + for (int j = i * 2 + 1; j >= 1; j--) cout << c; cout << endl; } - for (int i = 0; i < row; i++) - cout << " "; + for (int i = 0; i < row; i++) cout << " "; cout << c << endl; for (int i = 1; i <= row; i++) { - for (int k = row - i; k >= 1; k--) - cout << " "; - for (int j = i * 2 + 1; j >= 1; j--) - cout << c; + for (int k = row - i; k >= 1; k--) cout << " "; + for (int j = i * 2 + 1; j >= 1; j--) cout << c; cout << endl; } cout << (N - (2 * row * (row + 2) + 1)); diff --git "a/BasicLevel_C++/1031. \346\237\245\351\252\214\350\272\253\344\273\275\350\257\201(15).cpp" "b/BasicLevel_C++/1031. \346\237\245\351\252\214\350\272\253\344\273\275\350\257\201(15).cpp" index 5236e4f..852164d 100644 --- "a/BasicLevel_C++/1031. \346\237\245\351\252\214\350\272\253\344\273\275\350\257\201(15).cpp" +++ "b/BasicLevel_C++/1031. \346\237\245\351\252\214\350\272\253\344\273\275\350\257\201(15).cpp" @@ -3,26 +3,21 @@ using namespace std; bool func(string a); int main() { - int n; - int count = 0; + int n, count = 0; cin >> n; for (int i = 0; i < n; i++) { string a; cin >> a; if (func(a)) count++; } - if (count == 0) - cout << "All passed"; + if (count == 0) cout << "All passed"; return 0; } - bool func(string s) { - int sum = 0; - int a[18]; + int sum = 0, a[18]; for (int i = 0; i < 17; i++) a[i] = s[i] - '0'; - if (s[17] == 'X') - a[17] = 10; + if (s[17] == 'X') a[17] = 10; else a[17] = s[17] - '0'; int b[17] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}; diff --git "a/CCCC-GPLT/L1-002. \346\211\223\345\215\260\346\262\231\346\274\217 .cpp" "b/CCCC-GPLT/L1-002. \346\211\223\345\215\260\346\262\231\346\274\217 .cpp" index 179a840..72e0ff3 100644 --- "a/CCCC-GPLT/L1-002. \346\211\223\345\215\260\346\262\231\346\274\217 .cpp" +++ "b/CCCC-GPLT/L1-002. \346\211\223\345\215\260\346\262\231\346\274\217 .cpp" @@ -1,44 +1,27 @@ -include +#include using namespace std; int main() { - int N; - cin >> N; + int N, row = 0; char c; - cin >> c; - //计算行数row,只计算一半的行数,不包括最中间的那个一个符号 - int row = 0; - for (int i = 1; i < N; i++) { + cin >> N >> c; + for (int i = 0; i < N; i++) { if ((2 * i * (i + 2) + 1) > N) { row = i - 1; break; } } - // 打印上半部分 for (int i = row; i >= 1; i--) { - for (int k = row - i; k >= 1; k--) { - cout << " "; - } - for (int j = i * 2 + 1; j >= 1; j--) { - cout << c; - } + for (int k = row - i; k >= 1; k--) cout << " "; + for (int j = i * 2 + 1; j >= 1; j--) cout << c; cout << endl; } - // 打印中间的那个符号 - for (int i = 0; i < row; i++) { - cout << " "; - } + for (int i = 0; i < row; i++) cout << " "; cout << c << endl; - // 打印下半部分 for (int i = 1; i <= row; i++) { - for (int k = row - i; k >= 1; k--) { - cout << " "; - } - for (int j = i * 2 + 1; j >= 1; j--) { - cout << c; - } + for (int k = row - i; k >= 1; k--) cout << " "; + for (int j = i * 2 + 1; j >= 1; j--) cout << c; cout << endl; } - // 输出还剩下几个符号没有用 - cout << (N - (2 * row * (row + 2) + 1)); + cout << (N - (2 * row * (row + 2) + 1)); return 0; } \ No newline at end of file diff --git "a/CCCC-GPLT/L1-003. \344\270\252\344\275\215\346\225\260\347\273\237\350\256\241 .cpp" "b/CCCC-GPLT/L1-003. \344\270\252\344\275\215\346\225\260\347\273\237\350\256\241 .cpp" index 46f0b8d..db35c52 100644 --- "a/CCCC-GPLT/L1-003. \344\270\252\344\275\215\346\225\260\347\273\237\350\256\241 .cpp" +++ "b/CCCC-GPLT/L1-003. \344\270\252\344\275\215\346\225\260\347\273\237\350\256\241 .cpp" @@ -6,13 +6,9 @@ int main() { cin >> s; int len = s.length(); int a[10] = {0}; - for (int i = 0; i < len; i++) { - a[s[i] - '0']++; - } + for (int i = 0; i < len; i++) a[s[i] - '0']++; for (int i = 0; i < 10; i++) { - if (a[i] != 0) { - cout << i << ":" << a[i] << endl; - } + if (a[i] != 0) cout << i << ":" << a[i] << endl; } return 0; } \ No newline at end of file diff --git "a/CCCC-GPLT/L1-005. \350\200\203\350\257\225\345\272\247\344\275\215\345\217\267 .cpp" "b/CCCC-GPLT/L1-005. \350\200\203\350\257\225\345\272\247\344\275\215\345\217\267 .cpp" index 0b982f0..6b21772 100644 --- "a/CCCC-GPLT/L1-005. \350\200\203\350\257\225\345\272\247\344\275\215\345\217\267 .cpp" +++ "b/CCCC-GPLT/L1-005. \350\200\203\350\257\225\345\272\247\344\275\215\345\217\267 .cpp" @@ -1,29 +1,23 @@ #include +#include using namespace std; struct stu { string s; - int one; - int two; + int one, two; }; - int main() { - int n; + int n, m, temp; cin >> n; - stu *a = new stu [n]; + vector a(n); for (int i = 0; i < n; i++) { - cin >> a[i].s; - cin >> a[i].one; - cin >> a[i].two; + cin >> a[i].s >> a[i].one >> a[i].two; } - int m; cin >> m; - int temp; for (int i = 0; i < m; i++) { cin >> temp; for (int j = 0; j < n; j++) { if (a[j].one == temp) { - cout << a[j].s << " "; - cout << a[j].two << endl; + cout << a[j].s << " " << a[j].two << endl; break; } } diff --git "a/CCCC-GPLT/L1-006. \350\277\236\347\273\255\345\233\240\345\255\220.cpp" "b/CCCC-GPLT/L1-006. \350\277\236\347\273\255\345\233\240\345\255\220.cpp" index 2230c2a..0a65c10 100644 --- "a/CCCC-GPLT/L1-006. \350\277\236\347\273\255\345\233\240\345\255\220.cpp" +++ "b/CCCC-GPLT/L1-006. \350\277\236\347\273\255\345\233\240\345\255\220.cpp" @@ -1,33 +1,3 @@ -#include -#include -#include -using namespace std; -int main() { - int n; - scanf("%d", &n); - int max = sqrt(n); - for(int len = 12; len >= 1; len--) { - for(int start = 2; start <= max; start++) { - long long int ans = 1; - for(int i = start; i - start <= len - 1; i++) { - ans *= i; - } - if(n % ans == 0) { - printf("%d\n%d", len, start); - for(int i = start + 1; i - start <= len - 1; i++) { - printf("*%d", i); - } - return 0; - } - } - } - printf("1\n%d", n); - return 0; -} - -[Update v2.0] 由github用户littlesevenmo提供的更高效的解法 -不用算连续因子最多不会超过12个。也不需要三重循环,两重循环即可,直接去计算当前部分乘积能不能整除N,代码如下: - #include #include using namespace std; diff --git "a/CCCC-GPLT/L1-008. \346\261\202\346\225\264\346\225\260\346\256\265\345\222\214.cpp" "b/CCCC-GPLT/L1-008. \346\261\202\346\225\264\346\225\260\346\256\265\345\222\214.cpp" index 6c0ab89..74fd755 100644 --- "a/CCCC-GPLT/L1-008. \346\261\202\346\225\264\346\225\260\346\256\265\345\222\214.cpp" +++ "b/CCCC-GPLT/L1-008. \346\261\202\346\225\264\346\225\260\346\256\265\345\222\214.cpp" @@ -4,8 +4,7 @@ using namespace std; int main() { int a, b; cin >> a >> b; - int temp = a; - int sum = 0; + int temp = a, sum = 0; while(temp <= b) { for(int j = 0; j < 5 && temp <= b; j++) { printf("%5d", temp); diff --git "a/CCCC-GPLT/L1-010. \346\257\224\350\276\203\345\244\247\345\260\217.cpp" "b/CCCC-GPLT/L1-010. \346\257\224\350\276\203\345\244\247\345\260\217.cpp" index 2c95ba5..b309141 100644 --- "a/CCCC-GPLT/L1-010. \346\257\224\350\276\203\345\244\247\345\260\217.cpp" +++ "b/CCCC-GPLT/L1-010. \346\257\224\350\276\203\345\244\247\345\260\217.cpp" @@ -3,15 +3,9 @@ using namespace std; int main() { int a, b, c; cin >> a >> b >> c; - if(b > c) { - swap(b, c); - } - if(a > b) { - swap(a, b); - } - if(b > c) { - swap(b, c); - } + if(b > c) swap(b, c); + if(a > b) swap(a, b); + if(b > c) swap(b, c); cout << a << "->" << b << "->" << c; return 0; } \ No newline at end of file diff --git a/CCCC-GPLT/L1-011. A-B.cpp b/CCCC-GPLT/L1-011. A-B.cpp index 5ab0f3d..d2c831a 100644 --- a/CCCC-GPLT/L1-011. A-B.cpp +++ b/CCCC-GPLT/L1-011. A-B.cpp @@ -5,13 +5,9 @@ int main() { string s, a; getline(cin, s); getline(cin, a); - for(int i = 0; i < a.length(); i++) { - book[a[i]] = 1; - } + for(int i = 0; i < a.length(); i++) book[a[i]] = 1; for(int i = 0; i < s.length(); i++) { - if(book[s[i]] == 1) { - continue; - } + if(book[s[i]] == 1) continue; cout << s[i]; } return 0; diff --git "a/CCCC-GPLT/L1-013. \350\256\241\347\256\227\351\230\266\344\271\230\345\222\214.cpp" "b/CCCC-GPLT/L1-013. \350\256\241\347\256\227\351\230\266\344\271\230\345\222\214.cpp" index e675581..34b1c26 100644 --- "a/CCCC-GPLT/L1-013. \350\256\241\347\256\227\351\230\266\344\271\230\345\222\214.cpp" +++ "b/CCCC-GPLT/L1-013. \350\256\241\347\256\227\351\230\266\344\271\230\345\222\214.cpp" @@ -1,14 +1,11 @@ #include using namespace std; int main() { - int n; + int n, ans = 0; cin >> n; - int ans = 0; for(int i = 1; i <= n; i++) { int temp = 1; - for(int j = 1; j <= i; j++) { - temp *= j; - } + for(int j = 1; j <= i; j++) temp *= j; ans += temp; } cout << ans; diff --git "a/CCCC-GPLT/L1-016. \346\237\245\351\252\214\350\272\253\344\273\275\350\257\201.cpp" "b/CCCC-GPLT/L1-016. \346\237\245\351\252\214\350\272\253\344\273\275\350\257\201.cpp" index 9f15eda..852164d 100644 --- "a/CCCC-GPLT/L1-016. \346\237\245\351\252\214\350\272\253\344\273\275\350\257\201.cpp" +++ "b/CCCC-GPLT/L1-016. \346\237\245\351\252\214\350\272\253\344\273\275\350\257\201.cpp" @@ -3,39 +3,31 @@ using namespace std; bool func(string a); int main() { - int n; - int flag = 0; + int n, count = 0; cin >> n; for (int i = 0; i < n; i++) { string a; cin >> a; - if (func(a)) - flag = 1; + if (func(a)) count++; } - if (flag == 0) - cout << "All passed"; + if (count == 0) cout << "All passed"; return 0; } - bool func(string s) { - int sum = 0; - int a[18]; - for(int i = 0; i < 18; i++) { + int sum = 0, a[18]; + for (int i = 0; i < 17; i++) a[i] = s[i] - '0'; - } - if(s[17] == 'X') { - a[17] = 10; - } + if (s[17] == 'X') a[17] = 10; + else + a[17] = s[17] - '0'; int b[17] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}; - for (int i = 0; i < 17; i++) { + for (int i = 0; i < 17; i++) sum = sum + a[i] * b[i]; - } sum = sum % 11; int c[11] = {1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2}; if (c[sum] != a[17]) { - for (int i = 0; i < 17; i++) { + for (int i = 0; i < 17; i++) cout << s[i]; - } if (a[17] != 10) cout << a[17] << endl; else diff --git "a/CCCC-GPLT/L1-017. \345\210\260\345\272\225\346\234\211\345\244\232\344\272\214.cpp" "b/CCCC-GPLT/L1-017. \345\210\260\345\272\225\346\234\211\345\244\232\344\272\214.cpp" index 22ed51d..dfc4284 100644 --- "a/CCCC-GPLT/L1-017. \345\210\260\345\272\225\346\234\211\345\244\232\344\272\214.cpp" +++ "b/CCCC-GPLT/L1-017. \345\210\260\345\272\225\346\234\211\345\244\232\344\272\214.cpp" @@ -6,17 +6,13 @@ int main() { cin >> s; int flag = (s[0] == '-' ? 1 : 0); int len = s.length(); - int bit = len - flag; - int cnt = 0; + int bit = len - flag, cnt = 0; for(int i = 0; i < len; i++) { - if(s[i] == '2') - cnt++; + if(s[i] == '2') cnt++; } double ans = (double)cnt / bit * 100; - if(flag == 1) - ans = ans * 1.5; - if((s[len-1] - '0') % 2 == 0) - ans = ans * 2; + if(flag == 1) ans = ans * 1.5; + if((s[len-1] - '0') % 2 == 0) ans = ans * 2; printf("%.2f%%", ans); return 0; } \ No newline at end of file diff --git "a/CCCC-GPLT/L1-021. \351\207\215\350\246\201\347\232\204\350\257\235\350\257\264\344\270\211\351\201\215.cpp" "b/CCCC-GPLT/L1-021. \351\207\215\350\246\201\347\232\204\350\257\235\350\257\264\344\270\211\351\201\215.cpp" index ea7f606..2692a98 100644 --- "a/CCCC-GPLT/L1-021. \351\207\215\350\246\201\347\232\204\350\257\235\350\257\264\344\270\211\351\201\215.cpp" +++ "b/CCCC-GPLT/L1-021. \351\207\215\350\246\201\347\232\204\350\257\235\350\257\264\344\270\211\351\201\215.cpp" @@ -1,6 +1,6 @@ #include using namespace std; int main() { - cout << "I'm gonna WIN!" << endl << "I'm gonna WIN!" << endl << "I'm gonna WIN!"; + cout << "I'm gonna WIN!\nI'm gonna WIN!\nI'm gonna WIN!"; return 0; } \ No newline at end of file diff --git "a/CCCC-GPLT/L1-022. \345\245\207\345\201\266\345\210\206\345\256\266.cpp" "b/CCCC-GPLT/L1-022. \345\245\207\345\201\266\345\210\206\345\256\266.cpp" index 068b12c..38901d1 100644 --- "a/CCCC-GPLT/L1-022. \345\245\207\345\201\266\345\210\206\345\256\266.cpp" +++ "b/CCCC-GPLT/L1-022. \345\245\207\345\201\266\345\210\206\345\256\266.cpp" @@ -1,9 +1,8 @@ #include using namespace std; int main() { - int n; + int n, cnta = 0, cntb = 0; cin >> n; - int cnta = 0, cntb = 0; for(int i = 0; i < n; i++) { int temp; cin >> temp; diff --git "a/CCCC-GPLT/L1-025. \346\255\243\346\225\264\346\225\260A+B.cpp" "b/CCCC-GPLT/L1-025. \346\255\243\346\225\264\346\225\260A+B.cpp" index 360d84e..a95e273 100644 --- "a/CCCC-GPLT/L1-025. \346\255\243\346\225\264\346\225\260A+B.cpp" +++ "b/CCCC-GPLT/L1-025. \346\255\243\346\225\264\346\225\260A+B.cpp" @@ -5,17 +5,12 @@ bool islegal(string s) { if(s.length() == 0) return false; for(int i = 0; i < s.length(); i++) { - if(!isdigit(s[i])) { - return false; - } + if(!isdigit(s[i])) return false; } int temp = stoi(s); - if(temp < 1 || temp > 1000) { - return false; - } + if(temp < 1 || temp > 1000) return false; return true; } - int main() { string a, b; string t; @@ -27,16 +22,11 @@ int main() { break; } } - if(!islegal(a)) { - a = "?"; - } - if(!islegal(b)) { - b = "?"; - } + if(!islegal(a)) a = "?"; + if(!islegal(b)) b = "?"; cout << a << " + " << b << " = "; if(a != "?" && b != "?") { - int atemp = stoi(a); - int btemp = stoi(b); + int atemp = stoi(a), btemp = stoi(b); cout << atemp + btemp; } else { cout << "?"; diff --git "a/CCCC-GPLT/L1-028. \345\210\244\346\226\255\347\264\240\346\225\260.cpp" "b/CCCC-GPLT/L1-028. \345\210\244\346\226\255\347\264\240\346\225\260.cpp" index 14f459e..be9eb29 100644 --- "a/CCCC-GPLT/L1-028. \345\210\244\346\226\255\347\264\240\346\225\260.cpp" +++ "b/CCCC-GPLT/L1-028. \345\210\244\346\226\255\347\264\240\346\225\260.cpp" @@ -2,25 +2,22 @@ #include using namespace std; bool isprime(int a) { - if(a == 1) - return false; - for(int i = 2; i <= sqrt(a); i++) { - if(a % i == 0) - return false; + if (a == 1) return false; + for (int i = 2; i <= sqrt(a); i++) { + if (a % i == 0) return false; } return true; } int main() { int n; cin >> n; - for(int i = 0; i < n; i++) { + for (int i = 0; i < n; i++) { int temp; cin >> temp; - if(isprime(temp)) { + if (isprime(temp)) cout << "Yes" << endl; - } else { + else cout << "No" << endl; - } } return 0; } \ No newline at end of file diff --git "a/CCCC-GPLT/L1-030. \344\270\200\345\270\256\344\270\200.cpp" "b/CCCC-GPLT/L1-030. \344\270\200\345\270\256\344\270\200.cpp" index af815ac..83dbebc 100644 --- "a/CCCC-GPLT/L1-030. \344\270\200\345\270\256\344\270\200.cpp" +++ "b/CCCC-GPLT/L1-030. \344\270\200\345\270\256\344\270\200.cpp" @@ -17,15 +17,11 @@ int main() { int j = n - 1, k = n - 1; for(int i = 0; i < n/2; i++) { if(stu[i].a == 1) { - while(stu[j].a == stu[i].a) { - j--; - } + while(stu[j].a == stu[i].a) j--; cout << stu[i].s << " " << stu[j].s << endl; j--; } else { - while(stu[k].a == stu[i].a) { - k--; - } + while(stu[k].a == stu[i].a) k--; cout << stu[i].s << " " << stu[k].s << endl; k--; } diff --git "a/CCCC-GPLT/L1-035. \346\203\205\344\272\272\350\212\202.cpp" "b/CCCC-GPLT/L1-035. \346\203\205\344\272\272\350\212\202.cpp" index cffea5e..a3d7b77 100644 --- "a/CCCC-GPLT/L1-035. \346\203\205\344\272\272\350\212\202.cpp" +++ "b/CCCC-GPLT/L1-035. \346\203\205\344\272\272\350\212\202.cpp" @@ -4,9 +4,7 @@ int main() { string a, b, str; int cnt = 0; while(cin >> str) { - if (str == ".") { - break; - } + if (str == ".") break; cnt++; if (cnt == 2) a = str; if (cnt == 14) b = str; diff --git "a/CCCC-GPLT/L1-040 \346\234\200\344\275\263\346\203\205\344\276\243\350\272\253\351\253\230\345\267\256.cpp" "b/CCCC-GPLT/L1-040 \346\234\200\344\275\263\346\203\205\344\276\243\350\272\253\351\253\230\345\267\256.cpp" deleted file mode 100644 index 708b070..0000000 --- "a/CCCC-GPLT/L1-040 \346\234\200\344\275\263\346\203\205\344\276\243\350\272\253\351\253\230\345\267\256.cpp" +++ /dev/null @@ -1,16 +0,0 @@ -#include -using namespace std; -int main() { - int n; - cin >> n; - for(int i = 0; i < n; i++) { - string s; - double num; - cin >> s >> num; - if(s == "M") - printf("%.2f\n",num / 1.09); - else - printf("%.2f\n",num * 1.09); - } - return 0; -} \ No newline at end of file diff --git "a/CCCC-GPLT/L1-041 \345\257\273\346\211\276250.cpp" "b/CCCC-GPLT/L1-041 \345\257\273\346\211\276250.cpp" index a3279d2..577a65e 100644 --- "a/CCCC-GPLT/L1-041 \345\257\273\346\211\276250.cpp" +++ "b/CCCC-GPLT/L1-041 \345\257\273\346\211\276250.cpp" @@ -6,7 +6,8 @@ int main() { cnt++; if(num == 250) { cout << cnt; - return 0; + break; } } + return 0; } diff --git "a/CCCC-GPLT/L1-044 \347\250\263\350\265\242.cpp" "b/CCCC-GPLT/L1-044 \347\250\263\350\265\242.cpp" new file mode 100644 index 0000000..90e6f11 --- /dev/null +++ "b/CCCC-GPLT/L1-044 \347\250\263\350\265\242.cpp" @@ -0,0 +1,21 @@ +#include +#include +using namespace std; +int main() { + map m; + m["Bu"] = "JianDao"; + m["JianDao"] = "ChuiZi"; + m["ChuiZi"] = "Bu"; + int k, cnt = 0; + string s; + cin >> k; + while(cin >> s) { + if(s == "End") return 0; + cnt++; + if(cnt % (k + 1) == 0) + cout << s << endl; + else + cout << m[s] << endl; + } + return 0; +} diff --git "a/CCCC-GPLT/L1-045 \345\256\207\345\256\231\346\227\240\346\225\214\345\244\247\346\213\233\345\221\274.cpp" "b/CCCC-GPLT/L1-045 \345\256\207\345\256\231\346\227\240\346\225\214\345\244\247\346\213\233\345\221\274.cpp" new file mode 100644 index 0000000..da16293 --- /dev/null +++ "b/CCCC-GPLT/L1-045 \345\256\207\345\256\231\346\227\240\346\225\214\345\244\247\346\213\233\345\221\274.cpp" @@ -0,0 +1,8 @@ +#include +using namespace std; +int main() { + string s; + cin >> s; + cout << "Hello " << s; + return 0; +} \ No newline at end of file diff --git "a/CCCC-GPLT/L1-046 \346\225\264\351\231\244\345\205\211\346\243\215.cpp" "b/CCCC-GPLT/L1-046 \346\225\264\351\231\244\345\205\211\346\243\215.cpp" new file mode 100644 index 0000000..3fbdb70 --- /dev/null +++ "b/CCCC-GPLT/L1-046 \346\225\264\351\231\244\345\205\211\346\243\215.cpp" @@ -0,0 +1,19 @@ +#include +using namespace std; +int main() { + int n, ans = 1, cnt = 1; + cin >> n; + while (ans < n) { + ans = ans * 10 + 1; + cnt++; + } + while(1){ + cout << ans / n; + if(ans % n == 0) break; + ans = (ans % n) * 10 + 1; + cnt++; + } + cout << ' ' << cnt; + return 0; +} + diff --git "a/CCCC-GPLT/L1-047 \350\243\205\347\235\241.cpp" "b/CCCC-GPLT/L1-047 \350\243\205\347\235\241.cpp" new file mode 100644 index 0000000..0a6ab2f --- /dev/null +++ "b/CCCC-GPLT/L1-047 \350\243\205\347\235\241.cpp" @@ -0,0 +1,13 @@ +#include +using namespace std; +int main() { + int n, heart, impluse; + string name; + cin >> n; + for(int i = 0; i < n; i++) { + cin >> name >> heart >> impluse; + if(heart < 15 || heart > 20 || impluse < 50 || impluse > 70) + cout << name << endl; + } + return 0; +} \ No newline at end of file diff --git "a/CCCC-GPLT/L1-048 \347\237\251\351\230\265A\344\271\230\344\273\245B.cpp" "b/CCCC-GPLT/L1-048 \347\237\251\351\230\265A\344\271\230\344\273\245B.cpp" new file mode 100644 index 0000000..b923f05 --- /dev/null +++ "b/CCCC-GPLT/L1-048 \347\237\251\351\230\265A\344\271\230\344\273\245B.cpp" @@ -0,0 +1,34 @@ +#include +using namespace std; +int a[110][110], b[110][110], ans[110][110]; +int ra, ca, rb, cb; +int f(int r, int c) { + int sum = 0; + for(int i = 1; i <= ca; i++) + sum += a[r][i] * b[i][c]; + return sum; +} +int main() { + cin >> ra >> ca; + for(int i = 1; i <= ra; i++) + for(int j = 1; j <= ca; j++) + cin >> a[i][j]; + cin >> rb >> cb; + for(int i = 1; i <= rb; i++) + for(int j = 1; j <= cb; j++) + cin >> b[i][j]; + if(ca != rb) + printf("Error: %d != %d", ca, rb); + else { + printf("%d %d\n", ra, cb); + for(int i = 1; i <= ra; i++) { + for(int j = 1; j <= cb; j++) { + if(j != 1) cout << ' '; + cout << f(i,j); + } + cout << endl; + } + } + return 0; +} + diff --git "a/CCCC-GPLT/L1-049 \345\244\251\346\242\257\350\265\233\345\272\247\344\275\215\345\210\206\351\205\215.cpp" "b/CCCC-GPLT/L1-049 \345\244\251\346\242\257\350\265\233\345\272\247\344\275\215\345\210\206\351\205\215.cpp" new file mode 100644 index 0000000..20ffef8 --- /dev/null +++ "b/CCCC-GPLT/L1-049 \345\244\251\346\242\257\350\265\233\345\272\247\344\275\215\345\210\206\351\205\215.cpp" @@ -0,0 +1,38 @@ +#include +#include +using namespace std; +int main() { + int n, sum = 0, cnt = 1, num[110] = {0}, id_school[100001] = {0}; + cin >> n; + vector> v(n+1); + for(int i = 1; i <= n; i++) + cin >> num[i]; + while(1) { + bool flag = true; + for(int i = 1; i < v.size(); i++) { + if(v[i].size() < num[i] * 10) { + if(id_school[cnt-1] != i) { + id_school[cnt] = i; + v[i].push_back(cnt); + cnt++; + } else { + id_school[cnt+1] = i; + v[i].push_back(cnt+1); + cnt = cnt + 2; + } + flag = false; + } + } + if(flag) break; + } + for(int i = 1; i < v.size(); i++) { + cout << "#" << i << endl; + for(int j = 0; j < v[i].size(); j++) { + if(j != 0 && j % 10 != 0) cout << " "; + if(j != 0 && j % 10 == 0) cout << endl; + cout << v[i][j]; + } + cout << endl; + } + return 0; +} \ No newline at end of file diff --git "a/CCCC-GPLT/L1-050 \345\200\222\346\225\260\347\254\254N\344\270\252\345\255\227\347\254\246\344\270\262.cpp" "b/CCCC-GPLT/L1-050 \345\200\222\346\225\260\347\254\254N\344\270\252\345\255\227\347\254\246\344\270\262.cpp" new file mode 100644 index 0000000..7e80e32 --- /dev/null +++ "b/CCCC-GPLT/L1-050 \345\200\222\346\225\260\347\254\254N\344\270\252\345\255\227\347\254\246\344\270\262.cpp" @@ -0,0 +1,19 @@ +#include +#include +#include +using namespace std; +int main() { + int l, n, num; + cin >> l >> n; + vector v; + num = pow(26,l) - n ; + while(num) { + v.push_back(num % 26); + num /= 26; + } + for(int i = 0; i < l - v.size(); i++) + cout << 'a'; + for(int i = v.size() - 1; i >= 0; i--) + cout << (char)('a' + v[i]); + return 0; +} \ No newline at end of file diff --git "a/CCCC-GPLT/L1-051 \346\211\223\346\212\230.cpp" "b/CCCC-GPLT/L1-051 \346\211\223\346\212\230.cpp" new file mode 100644 index 0000000..f7a482d --- /dev/null +++ "b/CCCC-GPLT/L1-051 \346\211\223\346\212\230.cpp" @@ -0,0 +1,7 @@ +#include +int main() { + int a, b; + scanf("%d%d", &a, &b); + printf("%.2f", a * b * 0.1); + return 0; +} \ No newline at end of file diff --git "a/CCCC-GPLT/L1-052 2018\346\210\221\344\273\254\350\246\201\350\265\242.cpp" "b/CCCC-GPLT/L1-052 2018\346\210\221\344\273\254\350\246\201\350\265\242.cpp" new file mode 100644 index 0000000..c7d9db0 --- /dev/null +++ "b/CCCC-GPLT/L1-052 2018\346\210\221\344\273\254\350\246\201\350\265\242.cpp" @@ -0,0 +1,5 @@ +#include +int main() { + printf("2018\nwo3 men2 yao4 ying2 !"); + return 0; +} \ No newline at end of file diff --git "a/CCCC-GPLT/L1-053 \347\224\265\345\255\220\346\261\252.cpp" "b/CCCC-GPLT/L1-053 \347\224\265\345\255\220\346\261\252.cpp" new file mode 100644 index 0000000..1f818cf --- /dev/null +++ "b/CCCC-GPLT/L1-053 \347\224\265\345\255\220\346\261\252.cpp" @@ -0,0 +1,8 @@ +#include +int main() { + int a, b; + scanf("%d%d", &a, &b); + for(int i = 0; i < a + b; i++) + printf("Wang!"); + return 0; +} \ No newline at end of file diff --git "a/CCCC-GPLT/L1-054 \347\246\217\345\210\260\344\272\206.cpp" "b/CCCC-GPLT/L1-054 \347\246\217\345\210\260\344\272\206.cpp" new file mode 100644 index 0000000..dcab3d3 --- /dev/null +++ "b/CCCC-GPLT/L1-054 \347\246\217\345\210\260\344\272\206.cpp" @@ -0,0 +1,28 @@ +#include +#include +using namespace std; +int main() { + char c; + int n, flag = 0; + scanf("%c%d",&c, &n); + getchar(); + vector a(n), b(n); + for(int i = 0; i < n; i++) + getline(cin,a[i]); + for(int i = 0; i < n; i++) + for(int j = 0; j < n; j++) + if(a[i][j] != a[n-1-i][n-1-j]) + flag = 1; + if(flag == 0) cout << "bu yong dao le\n"; + for(int i = 0; i < n; i++) { + for(int j = 0; j < n; j++) { + if(a[n-1-i][n-1-j] == '@') + cout << c; + else + cout << " "; + } + cout << endl; + } + return 0; +} + diff --git "a/CCCC-GPLT/L1-055 \350\260\201\346\230\257\350\265\242\345\256\266.cpp" "b/CCCC-GPLT/L1-055 \350\260\201\346\230\257\350\265\242\345\256\266.cpp" new file mode 100644 index 0000000..7a9da44 --- /dev/null +++ "b/CCCC-GPLT/L1-055 \350\260\201\346\230\257\350\265\242\345\256\266.cpp" @@ -0,0 +1,12 @@ +#include +using namespace std; +int main() { + int votea, voteb, adj1, adj2, adj3, suma; + cin >> votea >> voteb >> adj1 >> adj2 >> adj3; + suma= 3 - (adj1 + adj2 + adj3); + if(suma == 3 || (suma >= 1 && votea > voteb)) + printf("The winner is a: %d + %d", votea, suma); + else + printf("The winner is b: %d + %d", voteb, 3-suma); + return 0; +} diff --git "a/CCCC-GPLT/L1-056 \347\214\234\346\225\260\345\255\227.cpp" "b/CCCC-GPLT/L1-056 \347\214\234\346\225\260\345\255\227.cpp" new file mode 100644 index 0000000..61cb2e5 --- /dev/null +++ "b/CCCC-GPLT/L1-056 \347\214\234\346\225\260\345\255\227.cpp" @@ -0,0 +1,21 @@ +#include +#include +using namespace std; +int main() { + int n, t, sum = 0, mindet = 1000, minid; + string name, a[110]; + cin >> n; + for(int i = 0; i < n; i++) { + cin >> name >> t; + a[t] = name; + sum += t; + } + double avg = 0.5 * sum / n; + for(int i = 0; i <= 100; i++) + if(a[i] != "" && abs(avg - i) < mindet) { + minid = i; + mindet = abs(avg - i); + } + cout << (int)avg << " " << a[minid]; + return 0; +} diff --git "a/CCCC-GPLT/L2-004. \350\277\231\346\230\257\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\220\227\357\274\237.cpp" "b/CCCC-GPLT/L2-004. \350\277\231\346\230\257\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\220\227\357\274\237.cpp" index 1dc51e0..c1ac101 100644 --- "a/CCCC-GPLT/L2-004. \350\277\231\346\230\257\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\220\227\357\274\237.cpp" +++ "b/CCCC-GPLT/L2-004. \350\277\231\346\230\257\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\345\220\227\357\274\237.cpp" @@ -2,8 +2,7 @@ #include using namespace std; bool isMirror; -vector pre; -vector post; +vector pre, post; void getpost(int root, int tail) { if(root > tail) return ; int i = root + 1, j = tail; diff --git "a/CCCC-GPLT/L2-005. \351\233\206\345\220\210\347\233\270\344\274\274\345\272\246.cpp" "b/CCCC-GPLT/L2-005. \351\233\206\345\220\210\347\233\270\344\274\274\345\272\246.cpp" index 20c129b..5faf1cf 100644 --- "a/CCCC-GPLT/L2-005. \351\233\206\345\220\210\347\233\270\344\274\274\345\272\246.cpp" +++ "b/CCCC-GPLT/L2-005. \351\233\206\345\220\210\347\233\270\344\274\274\345\272\246.cpp" @@ -20,11 +20,10 @@ int main() { scanf("%d %d", &a, &b); int nc = 0, nt = v[b-1].size(); for(auto it = v[a-1].begin(); it != v[a-1].end(); it++) { - if(v[b-1].find(*it) == v[b-1].end()) { + if(v[b-1].find(*it) == v[b-1].end()) nt++; - } else { + else nc++; - } } double ans = (double)nc / nt * 100; printf("%.2f%%\n", ans);