じゃっかんきおくそうしつしたもんだいたち
2503
Trie木の練習のため、他人のコードをほぼてコピ。いや、木のところだけ。
struct trie{ trie *next[26]; char *val; trie() {for(int i=0; i<26; i++) next[i]=(trie*)0; val=(char*)0;} }; trie start; void add_node(char str[], char value[]) { trie *cur = &start; for (int p=0; str[p]; p++) { if (!cur->next[str[p]-'a']) cur->next[str[p]-'a'] = new trie; cur = cur->next[str[p]-'a']; } cur->val = value; } char* find_node(char str[]) { trie *cur = &start; for (int p=0; str[p]; p++) { if (!cur->next[str[p]-'a']) return "eh"; cur = cur->next[str[p]-'a']; } return cur->val; } #include <cstdio> #include <cstring> char line[30]; int main() { char key[12]; while (gets(line)) { if (strlen(line) < 2) break; char* value = new char[12]; sscanf(line, "%s %s",value,key); add_node(key, value); } while (gets(line)) { if (sscanf(line, "%s", key)==EOF) break; char *ans = find_node(key); printf("%s\n", ans?ans:"eh"); } }
1423
数学問、わかんねぇよとカンニング
#include <cstdio> #include <cmath> #define ME 2.71828183 #define MPI 3.14159265 int main() { int n, m; scanf("%d", &n); for (int i=0; i<n; i++) { scanf("%d", &m); int t=m*log10(m)-m*log10(ME)+log10(2*MPI*m)/2.0+1; if (m < 2) t = 1; printf("%d\n", t); } }
1338
最小経路問題っぽいって。カンニング
#include <set> #include <cstdio> #include <vector> using namespace std; typedef long long ll; int main() { set<ll> q; q.insert(1); vector<int> ans; while (ans.size() < 1500) { const ll val = *q.begin(); q.erase(q.begin()); ans.push_back(val); q.insert(val*2); q.insert(val*3); q.insert(val*5); } int n; while (scanf("%d", &n) && n != 0) printf("%d\n", ans[n-1]); }
2484
最初自力でやったんだけど問題文読み間違えでおち。
あとで蟻本の訳見て解説見て書いた。
#include <cstdio> int main() { int n; while (scanf("%d",&n)&&n!=0) { if (n>2) printf("Bob\n"); else printf("Alice\n"); } }
2509
問題忘れた
#include <cstdio> int main() { int n, k; while (scanf("%d%d", &n, &k) != EOF) { int res = n, tmp = n; while (1) { res += tmp/k; tmp = tmp/k + tmp%k; if (tmp < k) break; } printf("%d\n", res); } }
2685
書くだけ。めんどい
#include <iostream> #include <cstring> using namespace std; int toInt(string mcxi) { int tmp = 1; int res = 0; for (int i=0; i<mcxi.length(); i++) { if (isdigit(mcxi[i])) { tmp = mcxi[i] - '0'; } else { int x; if (mcxi[i] == 'm') x = 1000; else if (mcxi[i] == 'c') x = 100; else if (mcxi[i] == 'x') x = 10; else x = 1; res += x * tmp; tmp = 1; } } return res; } string toStr(int num) { int m, c, x, i; string res = ""; m = num / 1000; if (m != 0) { num -= m * 1000; if (m != 1) res += (m + '0'); res += "m"; } c = num / 100; if (c != 0) { num -= c * 100; if (c != 1) res += (c + '0'); res += "c"; } x = num / 10; if (x != 0) { num -= x * 10; if (x != 1) res += (x + '0'); res += "x"; } i = num; if (i != 0) { if (i != 1) res += (i + '0'); res += "i"; } return res; } int main() { int t; cin >> t; for (int i=0; i<t; i++) { string str1, str2; cin >> str1 >> str2; cout << toStr(toInt(str1)+toInt(str2)) << endl; } }
2871
やるだけ
#include <iostream> #include <cstdio> using namespace std; int main() { float bn, n; cin >> bn; while (cin >> n) { if (n == 999) { cout << "End of Output" << endl; break; } printf("%.2f\n", n - bn); bn = n; } }
3077
頑張る問題
#include <cstdio> int main() { int n; scanf("%d", &n); for (int i=0; i<n; i++) { int x; scanf("%d",&x); int ten = 10; for (int i=0; i<8; i++) { if (x<ten) break; int tmp = x % ten; if (tmp >= 5*ten/10) x += ten; x -= tmp; ten *= 10; } printf("%d\n", x); } }
3085
書くだけ
#include <cstdio> int main() { int N, C; scanf("%d",&N); for (int i=0; i<N; i++) { scanf("%d",&C); int Q, D, n, P; Q = C / 25; C -= Q * 25; D = C / 10; C -= D * 10; n = C / 5; C -= n * 5; P = C; printf("%d %d QUARTER(S), %d DIME(S), %d NICKEL(S), %d PENNY(S)\n", i+1, Q, D, n, P); } }
3751
めんどい
#include <cstdio> int main() { int T,y,mon,d,h,m,s; scanf("%d",&T); for (int i=0; i<T; i++) { scanf("%d/%d/%d-%d:%d:%d",&y,&mon,&d,&h,&m,&s); bool am = true; if (h>=12 && h<24) { am = false; if (h != 12) h -= 12; } else if (h == 0) { h = 12; } if (am) { printf("%02d/%02d/%4d-%02d:%02d:%02dam\n",mon,d,y,h,m,s); } else { printf("%02d/%02d/%4d-%02d:%02d:%02dpm\n",mon,d,y,h,m,s); } } }
総評
最初のほうのカンニング率wwwこれで80問いきました。