2010-01-01から1年間の記事一覧

AOJ 0084 Search Engine

404 Not Found #include <cstdio> #include <vector> #include <string> using namespace std; int main() { vector<string> v,w; string s(""); char c; while(c = getchar(), ~c){ switch(c){ case ' ': case ',': case '.': if(s != "") v.push_back(s); s = c; v.push_back(s); s = ""; b</string></string></vector></cstdio>…

AOJ 0046 Differential

404 Not Found #include <vector> #include <cstdio> #include <algorithm> using namespace std; int main() { double n; vector<double> v; while(~scanf("%lf", &n)) v.push_back(n); sort(v.begin(), v.end()); printf("%.1lf\n", *v.rbegin() - *v.begin()); return 0; }</double></algorithm></cstdio></vector>

AOJ 0077 Run Length

404 Not Found #include <cstdio> #include <cstring> int main() { char s[101]; while(fgets(s, 101, stdin)){ for(int i = 0, l = strlen(s); i < l; i++){ if(s[i] == '@'){ for(int j = 0; j < s[i + 1] - '0'; j++) putchar(s[i + 2]); i += 2; }else{ putchar(s[i]); }</cstring></cstdio>…

AOJ 0051 Differential II

404 Not Found #include <cstdio> #include <vector> #include <cstdlib> #include <algorithm> using namespace std; int main() { int n; char s[9]; scanf("%d\n", &n); for(int i = 0; i < n; i++){ int max, min; vector<int> v; scanf("%8s", s); for(int j = 0; j < 8; j++) v.push_back(s[j] -</int></algorithm></cstdlib></vector></cstdio>…

AOJ 0028 Mode Value

404 Not Found #include <cstdio> #include <map> #include <vector> #include <algorithm> using namespace std; int main() { map <int, int> m; map <int, vector<int> > l; int n; while(~scanf("%d\n", &n)) m[n]++; for(map<int, int>::iterator it = m.begin(); it != m.end(); it++) l[(*it).second].push_back((*i…</int,></int,></int,></algorithm></vector></map></cstdio>

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>…

二日間のAnarchy Golfの成果

id:kyuridenamidaが昨日から遊びにきて、今日の夜に帰っていった。他にやる事もないので結局プログラミング合宿風になった。 延々とLinux CafeでCode Golfをしたりして遊んだ。 ちなみに合宿中は僕が今壊れてないノートPCを持っていないのもあってperyaudena…

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>