2014-08-01から1ヶ月間の記事一覧

0065 - Trading

#include <algorithm> #include <cstdio> #include <cstdlib> #include <iostream> #include <map> #include <string> using namespace std; void Slove(void) { string s; map<int,int> before, next; while ( getline(cin,s) ) { if ( s.empty() ) break; int number=atoi( s.c_str() ); if ( !before.count(number) ) b</int,int></string></map></iostream></cstdlib></cstdio></algorithm>…

0064 - Secret Number

#include <iostream> using namespace std; int Slove(string word) { int number[80], sum=0; for (int i=0; i</iostream>

0063 - Palindrome

#include <iostream> #include <string> using namespace std; bool Slove(string word) { int i; for (i=0; i<word.length()/2; ++i) if ( word[i] != word[ (word.length()-1)-i ] ) break; return (i == word.length()/2)? true : false; } int main(void) { int count=0; string word; while (cin >> word) count+=Slov…</word.length()/2;></string></iostream>

0062 - What is the Bottommost?

#include <iostream> #include <string> using namespace std; void Slove(string str) { int number[10]; for (int i=0; i</string></iostream>

0061 - Rank Checker

#include <cstdio> #include <iostream> #include <queue> #include <vector> using namespace std; typedef pair<int,int> P_II; void Slove(void) { int number, point, before_number, before_point, team; vector<int> rank(1000,1); priority_queue< P_II,vector<P_II> > que; while ( scanf ("%d,%d", &numbe</p_ii></int></int,int></vector></queue></iostream></cstdio>…

0060 - Card Game

#include <iostream> using namespace std; void Slove(int C1, int C2, int C3) { int count=0; for (int i=1; i<=10; ++i) if (i!=C1 && i!=C2 && i!=C3 && C1+C2+i<=20) ++count; cout << (count > 3? "YES" : "NO") << endl; } int main(void) { int C1, C2, C3; w</iostream>…

0059 - Intersection of Rectangles

#include <iostream> using namespace std; void Slove(double xa1, double ya1, double xa2, double ya2, double xb1, double yb1, double xb2, double yb2) { cout << (xa1<=xb2 && xb1<=xa2 && ya1<=yb2 && yb1<=ya2? "YES" : "NO") << endl; } int main(void) { do</iostream>…

0057 - The Number of Area

#include <iostream> using namespace std; void Slove(int n) { cout << (n*n+n+2)/2 << endl; } int main(void) { int n; while (cin >> n) Slove(n); return 0; } 階差数列.....</iostream>

0056 - Goldbach's Conjecture

#include <iostream> using namespace std; #define MAX 50000 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>…

0055 - Sequence

#include <cstdio> #include <iostream> using namespace std; void Slove(double a) { double s=a; for (int i=2; i<=10; ++i) s+=(i%2)? a/=3 : a*=2; printf ("%.8lf\n", s); } int main(void) { double a; while (cin >> a) Slove(a); return 0; } やるだけ。</iostream></cstdio>

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