Algorithm

AOJ 0052 Factorial II

404 Not Found #include <cstdio> int main() { int n, a; while(a = 0, scanf("%d\n", &n), n){ while(n /= 5) a += n; printf("%d\n", a); } return 0; } すいません、解き方ぐぐりました。 階乗の末尾の 0 の個数数学的知識は乏しいのでそれぞれ覚えていくしかな</cstdio>…

AOJ 0049 Blood Group

404 Not Found #include <cstdio> #include <string> #include <map> using namespace std; int main() { char s[3]; map<string, int> m; while(~scanf("%*d,%2s", s)) m[string(s)]++; printf("%d\n%d\n%d\n%d\n", m["A"], m["B"], m["AB"], m["O"]); return 0; }</string,></map></string></cstdio>

AOJ 0031 Weight

404 Not Found #include <cstdio> #include <vector> using namespace std; int main() { int n; while(~scanf("%d\n", &n)){ vector<int> v; for(int i = 512; 1 <= i; i /= 2){ if(n < i) continue; n -= i; v.push_back(i); if(n <= 0) break; } for(int i = v.size() - 1; 0 <</int></vector></cstdio>…

SRM 479 DIV 2 250の過去問

数回TopCoderできなかったのでせめて過去問でも解く。 #include <vector> using namespace std; class TheAirTripDivTwo { public: int find(vector <int> flights, int fuel) { for(int i = 0; i < flights.size(); i++){ fuel -= flights[i]; if(fuel == 0) return i + </int></vector>…

AOJ 0048 Class

404 Not Found #include <cstdio> int main() { float n; int m; const char *rank[] = {"light fly", "fly", "bantam", "feather", "light", "light welter", "welter", "light middle", "middle", "light heavy", "heavy"}; while(~scanf("%f\n", &n)){ if(n <= 48</cstdio>…

AOJ 0047 Cup Game

404 Not Found #include <cstdio> #define swp(a,b) a ^= b,b ^= a,a ^= b; int main() { int cups[3] = {1, 0, 0}; unsigned char a, b; while(~scanf("%c,%c\n", &a, &b)) swp(cups[a - 'A'], cups[b - 'A']); printf("%c\n", cups[0] * 'A' + cups[1] * 'B' + cup</cstdio>…

AOJ 0061 Rank Checker

404 Not Found #include <map> #include <vector> #include <cstdio> using namespace std; int main(){ int n, m; map<int, vector<int> > l; vector<vector<int> > v; while(~scanf("%d,%d\n", &n, &m)){ if(!n && !m) break; l[m].push_back(n); } for(map<int, vector<int> >::reverse_iterator rit = l.rbegin(); rit …</int,></vector<int></int,></cstdio></vector></map>

K&RとCプログラマのためのアルゴリズムとデータ構造、読了

旅行に行ってきた。その移動中の待ち時間等で2冊ほど読み終えた。 K&R プログラミング言語C 第2版 ANSI規格準拠作者: B.W.カーニハン,D.M.リッチー,石田晴久出版社/メーカー: 共立出版発売日: 1989/06/15メディア: 単行本購入: 28人 クリック: 721回この商品…

AOJ 0075 BMI

404 Not Found #include <cstdio> int main() { int l; double m, n; while(~scanf("%d,%lf,%lf\n", &l, &m, &n)) if(25.0 <= m/(n*n)) printf("%d\n", l); return 0; }</cstdio>

AOJ 0020 Capitalize

404 Not Found #include <cstdio> int main() { char n; while(~(n = getchar())) putchar('a' <= n && n <= 'z' ? n - 'a' + 'A' : n); return 0; } あまり気合の入らないショートコーディング main(n){while(n=getchar(),~n)putchar(96</cstdio>

AOJ 0066 Tic Tac Toe

404 Not Found #include <cstdio> int main(){ char b[10], a[3][3]; while(~scanf("%9s\n", b)){ char r = 0; for(int i = 0; i < 9; i++) a[i%3][i/3] = b[i]; for(int i = 0, j, f; i < 3; i++){ if(a[i][0] == 's') continue; for(j = 0, f = 1; j < 3; j++) if(</cstdio>…

AOJ 0018 Sorting Five Numbers

404 Not Found #include <cstdio> #include <vector> #include <algorithm> using namespace std; int main(){ vector<int> v(5); for(int i = 0; i < 5; i++) scanf("%d", &v[i]); sort(v.rbegin(), v.rend()); for(int i = 0; i < 5; i++) printf("%d%c", v[i], i-4?' ':'\n'); return 0; }</int></algorithm></vector></cstdio>

AOJ 0025 Hit and Blow

#include <cstdio> int main(){ int a[4], b[4]; while(~scanf("%d %d %d %d\n%d %d %d %d\n", &a[0], &a[1], &a[2], &a[3], &b[0], &b[1], &b[2], &b[3])){ int hit = 0, blow = 0; for(int i = 0; i < 4; i++) for(int j = 0; j < 4; j++) if(a[i] == b[j]) if(i =</cstdio>…

AOJ 0029 English Sentence

#include <iostream> #include <string> #include <map> using namespace std; int main(){ string s, max(""); map<string, int> w; map<int, string> x; while(cin>>s){ if(s.size() > max.size()) max = s; w[s]++; } for(map<string, int>::iterator it = w.begin(); it != w.end(); it++) x[(*it).second] = (*it).fir…</string,></int,></string,></map></string></iostream>

AOJ 0026 Dropping Ink

#include <cstdio> int main(){ int x, y, sz, max = 0, cnt = 0; char si[3][3] = {{0, 1, 0}, {1, 1, 1}, {0, 1, 0}}, mi[3][3] = {{1,1,1},{1,1,1},{1,1,1}}, li[5][5] = {{0, 0, 1, 0, 0}, {0, 1, 1, 1, 0}, {1, 1, 1, 1, 1}, {0, 1, 1, 1, 0}, {0, 0, 1, 0, 0}}</cstdio>…

AOJ 0036 A Figure on Surface

404 Not Found #include <cstdio> int main(){ char m[12][12]; char fgr[7][4][4] = { {{1, 1, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, {{1, 0, 0, 0}, {1, 0, 0, 0}, {1, 0, 0, 0}, {1, 0, 0, 0}}, {{1, 1, 1, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0,</cstdio>…

AOJ 0033 Ball

404 Not Found #include <cstdio> #include <list> using namespace std; int main(){ int n; scanf("%d\n", &n); for(int i = 0, tmp; i < n; i++){ list<int> a, b, c; for(int j = 0; j < 10; a.push_back(tmp), j++) scanf("%d", &tmp); while(!a.empty()){ if(a.front() > </int></list></cstdio>…

AOJ 0017再チャレンジ失敗

前回のコードは少し思い当たる節があったので、1から書きなおしてみたが、これがまたRuntime Errorだとかよく分からないエラーを吐く。もうはやここまでくるとお手上げ感がある。 #include <cstdio> #include <vector> #include <string> using namespace std; int main(){ while(1){</string></vector></cstdio>…

AOJ 0017と0027が通らない

[誤答例]AOJ 0017 Caesar Chipher #include <cstdio> #include <cstring> inline int cmp(char *ha, const char *ne, int len){ for(int i = -128, f = 1; i <= 127; i++, f = 1){ for(int j = 0; j < len; j++) if(ha[j]+i != ne[j]) f = 0; if(f) return i; } return 0; } i</cstring></cstdio>…

AOJ 0013 Switching Railroad Cars

※AOJはショートコーディングをする場ではありません 短縮前 #include <cstdio> #include <vector> int main(){ int n; std::vector<int> v; while(scanf("%d\n", &n)+1){ if(n){ v.push_back(n); }else{ printf("%d\n", v.back()); v.pop_back(); } } return 0; } 短縮後 #include <cstdio></cstdio></int></vector></cstdio>…

AOJ 0011 Drawing Lots

今日はid:kyuridenamidaと延々とリナカフェでcode golfをしたり秋葉原をほっつき歩いたりした。 まだこれからコードを書く。東京タワーとか見に行っても楽しくないしいっその事コーディング合宿って事でもいいんじゃないかって話になってる。初期状態のvを1…

AOJ 1000 A + B Problem

気休め、のはずなのにアホみたいなミスして不要なTLEをしてしまった。 #include <cstdio> int main(){ int a, b; while(scanf("%d %d\n", &a, &b)+1) printf("%d\n", a + b); return 0; }</cstdio>

AOJ 0008 Sum of 4 Integers

#include <cstdio> #include <vector> #include <map> using namespace std; int main(){ int n; vector<int> v(4); map<vector<int>,bool> m; while(scanf("%d\n", &n)+1){ m.clear(); for(v[0] = 0; v[0] < 10; v[0]++) for(v[1] = 0; v[1] < 10; v[1]++) for(v[2] = 0; v[2] < 10; v[2]++) for(v</vector<int></int></map></vector></cstdio>…

AOJ 0007 Dept Hell

#include <cstdio> int main(){ int t,n; scanf("%d\n",&n); for(t=100000;n;n--){ t+=t/20; if(t%1000)t+=1000-t%1000; } printf("%d\n",t); } なんかひどい</cstdio>

AOJ 0006 Reverse Sequence

1回目は3'15"で解けたんだけども、Compile Error喰らって、その喰らった理由ってのも酷くてgets使ってんじゃねーぞ的な警告自体がエラーとされてて、仕方ないからfgetsにしたら今度はWA: Presentation Errorって出て、最後にputs("")っていう格好悪い事をし…

AOJ 0005 GCD and LCM

6'43"。まあもうちょっと早く解けてもいいかなあ。イチイチgcdの求め方をぐぐっているのもいただけない。 #include <cstdio> int main(){ long long unsigned int a, b, gcd, lcm; while(scanf("%llu %llu\n", &a, &b)+1){ long long unsigned int m, n, o; m = a; n</cstdio>…

AOJ 0004 Simultaneous Equation

だいたい11'ぐらい。手元でチマチマ方程式を解いただけ。 #include <cstdio> int main(){ int a, b, c, d, e, f; double x, y; while(scanf("%d %d %d %d %d %d\n", &a, &b, &c, &d, &e, &f) != EOF){ y = (double)(a * f - c * d) / (double)(a * e - b * d); x = (</cstdio>…

AOJ 0003 Is it a Right Triangle?

lvalue required as left operand of assignment、とかいう意味不明なエラーに悩ませられて結局==を=と書いてただけのポカミスだったと気付いて、結局8'39"だった。 #include <cstdio> int main(){ int N; scanf("%d", &N); for(int i = 0; i < N; i++){ int a, b, c</cstdio>…

AOJ 0002 Digit Number

1回目解答まで3'37"、しかし1回目はWrong Answerされた。 sprintfをsscanfって書いた。 解法で一瞬でも悩んじゃいけませんね。悩んだ時間で問題の単純かどうかとかはふっ飛ぶぐらいの時間が失なわれる。 #include <cstdio> int main(){ int a, b; char hoge[256]; wh</cstdio>…

AOJ 0001 List of Top 3 Hills

問題を開いてから書き終えるまで3'08"(手元のストップウォッチより)。 #include <cstdio> #include <vector> #include <algorithm> using namespace std; int main(){ vector<int> m(10); for(int i = 0; i < 10; i++) scanf("%d\n", &m[i]); sort(m.begin(), m.end()); for(int i = 0; i < 3</int></algorithm></vector></cstdio>…