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

10003 - Small, Large, or Equal

#include <iostream> using namespace std; void Slove(int a, int b) { if (a > b) cout << "a > b" << endl; else if (a < b) cout << "a < b" << endl; else cout << "a == b" << endl; } int main(void) { int a, b; cin >> a >> b; Slove(a,b); return 0; } やる</iostream>…

10002 - Rectangle

#include <iostream> using namespace std; void Slove(int a, int b) { cout << a*b << " " << 2*(a+b) << endl; } int main(void) { int a, b; cin >> a >> b; Slove(a,b); return 0; } やるだけ!</iostream>

10001 - X Cubic

#include <iostream> using namespace std; void Slove(int x) { cout << x*x*x << endl; } int main(void) { int x; cin >> x; Slove(x); return 0; } やるだけ問題。。</iostream>

10000 - Hello World

#include <iostream> using namespace std; void Slove(void) { cout << "Hello World" << endl; } int main(void) { Slove(); return 0; } やるだけ。。</iostream>

0093 - Leap Year

#include <iostream> using namespace std; bool Leap_Year(int year) { return ( ( !(year%400) || (!(year%4) && year%100) )? true : false ); } void Slove(int a, int b) { bool flg=false; for (int year=a; year<=b; ++year) if ( Leap_Year(year) ) { flg=true</iostream>…

0092 - Square Searching

#include <algorithm> #include <iostream> using namespace std; int dp[1000+1][1000+1]; void Init(int n) { for (int i=0; i<=n; ++i) for (int j=0; j<=n; ++j) dp[i][j]=0; } void Slove(int n) { int answer=0; char field[n+1][n+1]; Init(n); for (int i=1; i<=n; ++i) f</iostream></algorithm>…

0086 - Patrol

#include <iostream> using namespace std; void Slove(void) { int a, b; while (cin >> a >> b) { int graph[100]={0}; while ( !(!a && !b) ) { ++graph[--a]; ++graph[--b]; cin >> a >> b; } bool flg=true; if ( !(graph[1]%2) || !(graph[1]%2) ) flg=false; fo</iostream>…

0085 - Joseph's Potato

#include <iostream> using namespace std; void Slove(int n, int m) { int answer=1; for (int i=2; i<=n; ++i) { answer=(answer+m)%i; if (!answer) answer=i; } cout << answer << endl; } int main(void) { int n, m; while (cin >> n >> m && n) Slove(n,m); re</iostream>…

0084 - Search Engine

#include <iostream> #include <sstream> #include <string> using namespace std; void Slove(string str) { string word; stringstream ss; bool flg=false; for (int i=0; i<str.length(); ++i) if (str[i]=='.' || str[i]==',') str[i]=' '; ss << str; while (ss >> word) if (3<=word.length() && word.length()<=6) …</str.length();></string></sstream></iostream>

0083 - Era Name Transformation

#include <iostream> #include <string> using namespace std; void Slove(int year, int month, int day) { const string era[5]={"pre-meiji", "meiji", "taisho", "showa", "heisei"}; const long long int period[4]={18680908, 19120730, 19261225, 19890108}; long long </string></iostream>…

0080 - Third Root

#include <cstdio> #include <cmath> #include <iostream> using namespace std; void Slove(double q) { double x=q/2.0; while (fabs(x*x*x-q) >= 0.00001*q) x-=(x*x*x-q)/(3*x*x); printf ("%lf\n", x); } int main(void) { double q; cin >> q; while (q != -1) { Slove(q); cin </iostream></cmath></cstdio>…

0078 - Magic Square

#include <cstdio> #include <iostream> using namespace std; void Slove(int n) { int square[n][n]; for (int i=0; i<n; ++i) for (int j=0; j<n; ++j) square[i][j]=0; int x=n/2, y=(n+1)/2; square[y][x]=1; for (int number=2; number<=n*n; ++number) { ++x; ++y; while (true) { if (x >= n) x=0; if (x < 0) x=n-…</n;></iostream></cstdio>

0077 - Run Length

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

0075 - BMI

#include <cstdio> #include <iostream> #include <vector> using namespace std; typedef pair<int,double> P_ID; void Slove(void) { int number; double weight, height; vector<P_ID> vec; while (scanf ("%d,%lf,%lf", &number, &weight, &height) != EOF) vec.push_back( P_ID(number,25.0-weight/(</p_id></int,double></vector></iostream></cstdio>…

0074 - Videotape

#include <cstdio> #include <iostream> using namespace std; void Slove(int hour, int minute, int second) { int number=(2*3600)-(hour*3600+minute*60+second); printf ("%02d:%02d:%02d\n", number/3600, (number%3600)/60, number%3600%60 ); printf ("%02d:%02d:%02d\</iostream></cstdio>…

0073 - Surface Area of Quadrangular Pyramid

#include <cmath> #include <cstdio> #include <iostream> using namespace std; void Slove(int x, int h) { printf ("%5lf\n", x*sqrt(4*h*h+x*x)+x*x); } int main(void) { int x, h; while ( cin >> x >> h && (x || h) ) Slove(x,h); return 0; } 正四角錐の公式一発</iostream></cstdio></cmath>

0072 - Carden Lantern

#include <algorithm> #include <cstdio> #include <functional> #include <iostream> #include <queue> #include <utility> #include <vector> using namespace std; #define MAX_N 100 typedef pair<int,int> P_II; vector<P_II> G[MAX_N]; void Prim(int n) { int answer=0; bool used[n]; priority_queue< P_II,vector<…</p_ii></int,int></vector></utility></queue></iostream></functional></cstdio></algorithm>

0071 - Bombs Chain

#include <iostream> using namespace std; bool flg[8][8]; void dfs(int x, int y) { flg[y][x]=false; for (int k=1; k<=3; ++k) { if (flg[y][x+k] && x+k<8) dfs(x+k,y); if (flg[y+k][x] && y+k<8) dfs(x,y+k); if (flg[y][x-k] && 0<=x-k) dfs(x-k,y); if (flg[</iostream>…

0067 - The Number of Island

#include <iostream> #include <string> using namespace std; void dfs(string data[], int i, int j) { data[i][j]='0'; if (j<12-1 && data[i][j+1]=='1') dfs(data,i,j+1); if (i<12-1 && data[i+1][j]=='1') dfs(data,i+1,j); if (0</string></iostream>

0066 - Tic Tac Toe

#include <iostream> #include <string> using namespace std; void Slove(string data) { char result='d'; for (int i=0; i<3; ++i) { if ( data[i]==data[i+3] && data[i]==data[i+2*3] ) result=data[i]; if (result=='o' || result=='x') break; } for (int j=0; j<3; ++j</string></iostream>…

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>