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

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