#include <stdio.h> int main() { int T, C = 1; scanf("%d", &T); while (T--) { char s[1111]; scanf("%s", s); int i, j, ans = 0; for (i = 0; s[i]; i++) { int cnt[26] = {}, odd = 0; for (j = i; s[j]; j++) { odd += (cnt[s[j] - 'a'] & 1) ? -1 : 1; cnt[s[j] - 'a']++; ans += (odd <= 1); } } printf("Case %d: %d\n", C++, ans); } return 0; }
Hello, I am a CS student from Taiwan.
I am learing English and Programming.
I'll save source code of some problems or small programs without comments in this blog.
I would recommend you not to read solution from others before you solved the problem.
(這邊專門存放沒有任何註解的小程式/OJ題目程式碼)
2013年12月13日
UVa 12718 - Dromicpalin Substrings
UVa 12712 - Pattern Locker
#include <stdio.h> int main() { long long mod = 1e13 + 7; int T, C = 1; scanf("%d", &T); while (T--) { int L, M, N; scanf("%d%d%d", &L, &M, &N); L *= L; long long i, ans = 0, sum = 1; for (i = 0; i < M - 1; i++) { sum = (sum * (L - i)) % mod; } for (; M <= N; M++) { sum = (sum * (L - M + 1)) % mod; ans = (ans + sum) % mod; } printf("Case %d: %lld\n", C++, ans); } return 0; }
UVa 12709 - Falling Ants
#include <stdio.h> int main() { int T; while (scanf("%d", &T) && T) { int L, W, H; int maxH = 0, maxV = 0; while (T--) { scanf("%d%d%d", &L, &W, &H); int v = L * W * H; if (H > maxH || (H == maxH && v > maxV)) { maxH = H; maxV = v; } } printf("%d\n", maxV); } return 0; }
訂閱:
文章 (Atom)