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

0054 - Sum of Nth decimal places

#include <iostream> using namespace std; void Slove(int a, int b, int n) { int s=0, f=a%b; for (int i=0; i<n; ++i) { f*=10; s+=f/b; f%=b; } cout << s << endl; } int main(void) { int a, b, n; while (cin >> a >> b >> n) Slove(a,b,n); return 0; } 筆算の方法を書いただけ。</n;></iostream>

0053 - Sum of Prime Numbers

#include <iostream> using namespace std; #define MAX 1000000 bool is_prime[MAX+1]; void Sieve(void) { for (int i=0; i<=MAX; ++i) is_prime[i]=true; is_prime[0]=is_prime[1]=false; for (int i=2; i<=MAX; ++i) if ( is_prime[i] ) for (int j=i*2; j<=MAX; j</iostream>…

0052 - Factorial II

#include <iostream> using namespace std; void Slove(int n) { int count=0; while (n > 0) { count+=n/5; n/=5; } cout << count << endl; } int main(void) { int n; while (cin >> n && n) Slove(n); return 0; } 5で割った商を足していくと末尾の0の数になる。 (</iostream>…

0051 - Differential II

#include <algorithm> #include <functional> #include <iostream> using namespace std; #define DIGIT 10000000 int Alignment(int data[]) { int number=0, j=DIGIT; for (int i=0; i<8; ++i, j/=10) number+=data[i]*j; return number; } void Slove(int n) { int number, data[8], max_nu</iostream></functional></algorithm>…

0050 - Apple and Peach

#include <iostream> #include <string> using namespace std; void Slove(string str) { string apple="apple", peach="peach"; for (int i=0; i</string></iostream>

0049 - Blood Groups

#include <cstdio> #include <cstring> #include <iostream> using namespace std; void Slove(void) { int number, count[4]={0}; char blood[2+1]; while (scanf ("%d,%s", &number, blood) != EOF) { if ( !strcmp(blood,"A") ) ++count[0]; else if ( !strcmp(blood,"B") ) ++count[</iostream></cstring></cstdio>…

0048 - Class

#include <iostream> #include <string> using namespace std; void Slove(double w) { const string rank[11]={"light fly", "fly", "bantam", "feather", "light", "light welter", "welter", "light middle", "middle", "light heavy", "heavy"}; const double weight[10]={</string></iostream>…

0047 - Cup Game

#include <algorithm> #include <cstdio> #include <iostream> using namespace std; void Slove(void) { char a, b; bool ball[3]={true, false, false}; while (scanf (" %c,%c", &a, &b) != EOF) swap(ball[a-'A'],ball[b-'A']); for (int i=0; i<3; ++i) if ( ball[i] ) printf ("%c\n</iostream></cstdio></algorithm>…

0046 - Differential

#include <algorithm> #include <iostream> using namespace std; void Slove(void) { double high, max_high=0.0, min_high=10000.0; while (cin >> high) { max_high=max(max_high,high); min_high=min(min_high,high); } cout << max_high-min_high << endl; } int main(void) </iostream></algorithm>…

0045 - Sum and Average

#include <cstdio> #include <iostream> using namespace std; void Slove(void) { int money, number, count=0, sum=0; double average=0.0; while (scanf ("%d,%d", &money, &number) != EOF) { ++count; sum+=money*number; average+=(double)number; } cout << sum << endl</iostream></cstdio>…

0044 - Prime Number II

#include <iostream> using namespace std; #define MAX 100000 bool is_prime[MAX+1]; void Sieve(void) { for (int i=0; i<=MAX; ++i) is_prime[i]=true; is_prime[0]=is_prime[1]=false; for (int i=2; i<=MAX; ++i) if ( is_prime[i] ) for (int j=i*2; j<=MAX; j+</iostream>…

0043 - Puzzle

#include <iostream> #include <string> using namespace std; int Check(int number[]) { int sum=0; for (int i=1; i<10; ++i) sum+=number[i]; return sum; } void dfs(int number[], bool answer_flg[], int i) { if ( !Check(number) ) answer_flg[i]=true; else { for (i</string></iostream>…

0042 - A Thief

#include <cstdio> #include <iostream> using namespace std; int dp[1000+1][1000+1]; int Slove(int W, int number) { int N, value[1000], weight[1000], value_max=0, weight_max=0; cin >> N; for (int i=0; i<=N; ++i) for (int j=0; j<=W; ++j) dp[i][j]=0; for (int i</iostream></cstdio>…

0039 - Roman Figure

#include <iostream> #include <string> using namespace std; int arabia(char rome) { if (rome == 'I') return 1; else if (rome == 'V') return 5; else if (rome == 'X') return 10; else if (rome == 'L') return 50; else if (rome == 'C') return 100; else if (rome =</string></iostream>…

0038 - Poker Hand

#include <algorithm> #include <cstdio> #include <iostream> #include <string> using namespace std; void Slove(int hand[]) { int number_count[13]={0}, answer=0, rank=0; const string pattern[7]={"null", "one pair", "two pair", "three card", "straight", "full house", "four card"}</string></iostream></cstdio></algorithm>…

0036 - A Figure on Surface

#include <iostream> using namespace std; bool Slove(void) { int x=0, y=0; char grid[10][10]; for (int i=0; i<10; ++i) for (int j=0; j<10; ++j) grid[i][j]='0'; for (int i=0; i<8; ++i) for (int j=0; j<8; ++j) cin >> grid[i][j]; if ( cin.eof() ) return</iostream>…

0034 - Railway Lines

#include <cstdio> #include <iostream> using namespace std; void Slove(int l[], int v1, int v2) { int distance=0; for (int i=0; i<10; ++i) distance+=l[i]; double left_collision=(double)distance/(v1+v2)*v1; distance=0; for (int i=0; i<10; ++i) { distance+=l[i</iostream></cstdio>…

0033 - Ball

#include <iostream> using namespace std; bool flg; void dfs(int A[], int B, int C, int count) { if (count == 10) flg=true; else { if (B==0 && C==0) { dfs(A,A[count],C,count+1); dfs(A,B,A[count],count+1); } else { if (A[count] > B) dfs(A,A[count],C,c</iostream>…

0032 - Plastic Board

#include <cstdio> #include <iostream> using namespace std; int rectangle=0, lozenge=0; void Slove(int line1, int line2, int diagonal) { if (diagonal*diagonal == line1*line1+line2*line2) ++rectangle; if (line1 == line2) ++lozenge; } int main(void) { int line</iostream></cstdio>…

0031 - Weight

#include <iostream> #include <vector> using namespace std; void Slove(int weight) { vector<int> answer; answer.clear(); for (int w=(2<<8); w>=1; w/=2) if (w <= weight) { answer.push_back(w); weight-=w; } for (int i=answer.size()-1; i>=0; --i) { cout << answer[i]</int></vector></iostream>…

0030 - Sum of Integers

#include <iostream> using namespace std; int n, s, answer; void dfs(int number, int sum, int count) { if (n==count && s==sum) ++answer; if (number==10 || n==count) return; dfs(number+1,sum,count); dfs(number+1,sum+number,count+1); } void Slove(void)</iostream>…

0029 - English Sentence

#include <algorithm> #include <iostream> #include <map> #include <string> using namespace std; map<string,int> data; bool compare(const pair<string,int> T1, const pair<string,int> T2) { return T1.second < T2.second; } string Slove(string word, string max_length) { if (max_length.size() < word.size()…</string,int></string,int></string,int></string></map></iostream></algorithm>

0028 - Mode Value

#include <algorithm> #include <iostream> using namespace std; int number_count[100]={0}; void Slove(int max_count) { for (int i=0; i<100; ++i) if ( max_count == number_count[i] ) cout << i+1 << endl; } int main(void) { int max_count=0, number; while (cin >> nu</iostream></algorithm>…

0027 - What day is today?

#include <iostream> using namespace std; int Zeller(int year, int month, int day) { if (month==1 || month==2) { --year; month+=12; } return (year+year/4-year/100+year/400+(13*month+8)/5+day)%7; } void Slove(int month, int day) { string date[7]={"Sun</iostream>…

0026 - Dropping Ink

#include <algorithm> #include <cstdio> #include <iostream> using namespace std; int graph[10][10]; void Init(void) { for (int i=0; i<10; ++i) for (int j=0; j<10; ++j) graph[i][j]=0; } void Slove(int x, int y, int size) { const int dx[12]={1, 0, -1, 0, 1, -1, -1, 1, 2,</iostream></cstdio></algorithm>…

0025 - Hit and Blow

#include <iostream> using namespace std; void Slove(int a[]) { int b[4], hit=0, blow=0; for (int i=1; i<4; ++i) cin >> a[i]; for (int i=0; i<4; ++i) cin >> b[i]; for (int i=0; i<4; ++i) for (int j=0; j<4; ++j) if ( a[i] == b[j] ) { if (i == j) ++hit</iostream>…

0024 - Physical Experiments

#include <iostream> using namespace std; void Slove(double v) { int answer=0; double t=v/9.8, y=4.9*t*t; while (5*answer-5 <= (int)y) ++answer; cout << answer << endl; } int main(void) { double v; while (cin >> v) Slove(v); return 0; } 公式に当ては</iostream>…

0023 - Circles Intersection

#include <cmath> #include <iostream> using namespace std; void Slove(int n) { double xa, ya, ra, xb, yb, rb; for (int i=0; i<n; ++i) { cin >> xa >> ya >> ra >> xb >> yb >> rb; double center=sqrt( pow(xa-xb,2)+pow(ya-yb,2) ); if (center > ra+rb) cout << 0 << endl; else if </n;></iostream></cmath>…

0022 - Maximum Sum Sequence

#include <algorithm> #include <iostream> using namespace std; void Slove(int n) { int a[5000+1], sum; for (int i=0; i<n; ++i) cin >> a[i]; int max_sum=a[0]; for (int i=0; i<=n; ++i) { sum=0; for (int j=i; j</n;></iostream></algorithm>

0020 - Capitalize / AizuOnlineJudge

問題 : 大文字にする | Aizu Online Judge #include <cctype> #include <iostream> #include <string> using namespace std; void Solve(string str) { for (int i=0; i</string></iostream></cctype>