链接:Coder-Strike 2014 - Round 1
A题:看开始下标是接近左还是接近右,然后先移动到最左或最右,然后从左往右或重右往左一个个输出即可
B题:从大到小排个序,num[n]便是答案
C题:如果相同位置出现两个不同就肯定是‘?‘,如果只有一个就是该字母,如果都是‘?‘就输出a即可
D题:拓扑排序即可
E题:找到每个@位置,然后找中间一段直到‘.‘然后计算‘@‘前面有几个字符,‘.‘后面有几个字符,然后相乘,求总和
代码:
A:
#include <stdio.h> #include <string.h> int n, k, i, j; char ch[105]; int main() { scanf("%d%d", &n, &k); scanf("%s", ch); if (n - k < k) { for (i = k; i < n; i++) printf("RIGHT\n"); for (i = n - 1; i > 0; i--) { printf("PRINT %c\n", ch[i]); printf("LEFT\n"); } printf("PRINT %c\n", ch[0]); } else { for (i = 1; i < k; i++) printf("LEFT\n"); for (i = 0; i < n - 1; i++) { printf("PRINT %c\n", ch[i]); printf("RIGHT\n"); } printf("PRINT %c\n", ch[n - 1]); } return 0; }
#include <stdio.h> #include <string.h> #include<algorithm> using namespace std; int k, n, i; int num[105]; bool cmp(int a, int b) { return a > b; } int main() { scanf("%d%d", &k, &n); for (i = 1; i <= k; i++) scanf("%d", &num[i]); sort(num + 1, num + k + 1, cmp); printf("%d\n", num[n]); return 0; }
#include <stdio.h> #include <string.h> const int N = 100005; int n, vis[N], i, j; char str[N]; char ans[N]; int main() { scanf("%d", &n); int len; for (i = 0; i < n; i++) { scanf("%s", str); len = strlen(str); if (i == 0) { for (j = 0; j < len; j++) ans[j] = ‘?‘; } for (j = 0; j < len; j++) { if (vis[j]) continue; if (ans[j] == ‘?‘) { ans[j] = str[j]; } else { if (str[j] == ‘?‘) continue; if (ans[j] != str[j]) vis[j] = 1; } } } for (i = 0; i < len; i++) { if (vis[i]) printf("?"); else if (ans[i] == ‘?‘) printf("a"); else printf("%c", ans[i]); } printf("\n"); return 0; }
#include <stdio.h> #include <string.h> #include <vector> using namespace std; const int N = 30005; int n, m, ans[N], ansn, vis[N], i; vector<int> g[N]; void dfs(int u) { if (vis[u]) return; vis[u] = 1; for (int i = 0; i < g[u].size(); i++) { int v = g[u][i]; dfs(v); } ans[ansn++] = u; } int main() { scanf("%d%d", &n, &m); int u, v; while (m--) { scanf("%d%d", &u, &v); g[u].push_back(v); } for (i = 1; i <= n; i++) { if (vis[i]) continue; dfs(i); } for (i = 0; i < ansn - 1; i++) printf("%d ", ans[i]); printf("%d\n", ans[i]); return 0; }
#include <stdio.h> #include <string.h> const int N = 1000005; char str[N]; __int64 ans = 0, l, r, i, j, k; bool islettle(char c) { if (c >= ‘a‘ && c <= ‘z‘ || (c >= ‘A‘ && c <= ‘Z‘)) return true; return false; } int main() { scanf("%s", str); int n = strlen(str); for (i = 0; i < n; i++) { if (str[i] == ‘@‘) { l = 0; for (j = i - 1; j >= 0; j--) { if (str[j] == ‘@‘ || str[j] == ‘.‘) { break; } if (str[j] == ‘_‘ || !islettle(str[j])) continue; else l++; } for (j = i + 1; j < n; j++) { if (str[j] == ‘_‘ || str[j] == ‘@‘) { break; } if (str[j] == ‘.‘) { if (j == i + 1) break; for (k = j + 1; k < n; k++) { if (!islettle(str[k])) break; } ans += (k - j - 1) * l; i = j; break; } } } } printf("%I64d\n", ans); return 0; }
Coder-Strike 2014 - Round 1,布布扣,bubuko.com
原文:http://blog.csdn.net/accelerator_/article/details/24093279