AOJ

0140 - Bus Line

#include <iostream> #include <vector> using namespace std; void Slove(int n) { const int place[25]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; int a, b; for (int i=0; i<n; ++i) { cin >> a >> b; int start=0; while (place[start] != a) ++start</n;></vector></iostream>…

0139 - Snakes

#include <iostream> #include <string> using namespace std; int Check_A(string snake) { int first=0, second=0, i, j; for (i=2; i</string></iostream>

0138 - Track and Field Competition

#include <cstdio> #include <iostream> #include <map> using namespace std; void Slove(void) { int number; double time; map<double,int> top, third; third.clear(); for (int i=0; i<3; ++i) { top.clear(); for (int j=0; j<8; ++j) { cin >> number >> time; top.insert( map<double,int>::value_ty</double,int></double,int></map></iostream></cstdio>…

0137 - Middle-Square Method

#include <iostream> using namespace std; void Slove(int x) { int n, number[8]; for (int i=0; i<x; ++i) { cin >> n; cout << "Case " << i+1 << ":" << endl; for (int i=0; i<10; ++i) { n*=n; int tmp=n, answer=0; for (int j=0; j<8; ++j) { number[j]=tmp%10; tmp/=10; } in</x;></iostream>…

0136 - Frequency Distribution of Height

#include <iostream> using namespace std; void Slove(int n) { int count[6]={0}; double height; for (int i=0; i<n; ++i) { cin >> height; if (height < 165.0) ++count[0]; else if (height < 170.0) ++count[1]; else if (height < 175.0) ++count[2]; else if (height < 180.0)</n;></iostream>…

0135 - Clock Short Hand and Long Hand

#include <cmath> #include <cstdio> #include <iostream> using namespace std; void Slove(int n) { double hh, mm, angle_h, angle_m; for (int i=0; i</iostream></cstdio></cmath>

0134 - Exit Survey

#include <iostream> using namespace std; void Slove(int n) { int money; long long sum=0; for (int i=0; i<n; ++i) { cin >> money; sum+=money; } cout << sum/n << endl; } int main(void) { int n; cin >> n; Slove(n); return 0; } やるだけ。。</n;></iostream>

0128 - Abacus

#include <iostream> using namespace std; const string data[10]={ "* = ****", "* =* ***", "* =** **", "* =*** *", "* =**** ", " *= ****", " *=* ***", " *=** **", " *=*** *", " *=**** " }; void Slove(int number) { string answer[5]; for (int i=0; i<5; </iostream>…

0127 - Pocket Pager Input

#include <iostream> #include <string> using namespace std; const char data[6][6]= { {'a', 'f' ,'k', 'p', 'u', 'z'}, {'b', 'g', 'l', 'q', 'v', '.'}, {'c', 'h', 'm', 'r', 'w', '?'}, {'d', 'i', 'n', 's', 'x', '!'}, {'e', 'j', 'o', 't', 'y', ' '} }; void Slove(</string></iostream>…

0126 - Puzzle

#include <iostream> using namespace std; char data[9][9][2]; void CheckSide(int i) { int number[10]={0}; for (int j=0; j<9; ++j) ++number[data[i][j][0]-'0']; for (int j=0; j<9; ++j) if (number[data[i][j][0]-'0'] > 1) data[i][j][1]=1; } void CheckLen</iostream>…

0125 - Day Count

#include <cstdlib> #include <iostream> using namespace std; bool Leap_Year(int year) { if ( !(year%400) || (!(year%4) && year%100) ) return true; return false; } int Get_Sum(int year, int month, int day) { int month_data[12]={31, 28, 31, 30, 31, 30, 31, 31, </iostream></cstdlib>…

0124 - League Match Score Sheet

#include <functional> #include <iostream> #include <map> #include <string> using namespace std; void Slove(int n) { int win, draw, lose; string country; multimap< int,string,greater<int> > data; for (int i=0; i<n; ++i) { cin >> country >> win >> lose >> draw; data.insert( multimap<int,string>::value…</int,string></n;></int></string></map></iostream></functional>

0122 - Summer of Phyonkichi

#include <iostream> #include <queue> #include <string> using namespace std; const int dx[12]={2, 2, 1, 0, -1, -2, -2, -2, -1, 0, 1, 2}; const int dy[12]={0, 1, 2, 2, 2, 1, 0, -1, -2, -2, -2, -1}; struct DATA { int x, y, number; DATA(int a, int b, int c) {x=a; y=b;</string></queue></iostream>…

0121 - Seven Puzzle

#include <iostream> #include <map> #include <queue> #include <string> #include <utility> using namespace std; const int d[4]={-1, 1, -4, 4}; map<string,int> count; void bfs(void) { queue<string> que; que.push("01234567"); while ( !que.empty() ) { string wk1=que.front(); que.pop(); int pos=wk1.find</string></string,int></utility></string></queue></map></iostream>…

0118 - Property Distribution

#include <iostream> #include <string> using namespace std; int H, W; string field[100]; void dfs(int i, int j, char fruit) { field[i][j]='.'; if (j+1</string></iostream>

0117 - A reward for a Carpenter

#include <algorithm> #include <cstdio> #include <functional> #include <iostream> #include <queue> #include <vector> #include <utility> using namespace std; #define MAX_V 20 #define INF (1<<29) typedef pair<int,int> P_II; struct edge { int to, cost; edge(int a, int b) {to=a; cost=b;} }; vector<edge> …</edge></int,int></utility></vector></queue></iostream></functional></cstdio></algorithm>

0113 - Period

#include <algorithm> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; void Slove(int p, int q) { int index=-1; vector<int> vec; map<int,int> remain; remain[p%q]=0; p*=10; for (int i=0; i<80; ++i) { vec.push_back(p/q); if ( !(p%q) ) break; else if ( rem</int,int></int></vector></string></map></iostream></algorithm>…

0112 - A Milk Shop

#include <algorithm> #include <iostream> #include <vector> using namespace std; void Slove(int n) { int wait; vector<int> vec; vec.clear(); for (int i=0; i<n; ++i) { cin >> wait; vec.push_back(wait); } sort( vec.begin(),vec.end() ); long long sum=0; for (int i=0; i</n;></int></vector></iostream></algorithm>

0108 - Operation of Frequency of Appearance

#include <algorithm> #include <iostream> using namespace std; void Slove(int n) { int P[12], S[12], min_count=0, k; for (int k=0; k<n; ++k) cin >> S[k]; while (true) { fill(P,P+12,0); for (int i=0; i</n;></iostream></algorithm>

0107 - Carry a Cheese

#include <cmath> #include <iostream> using namespace std; void Slove(double a, double b, double c) { int n; double r; cin >> n; for (int i=0; i<n; ++i) { cin >> r; if ( pow(a/2.0,2)+pow(b/2.0,2)</n;></iostream></cmath>

0105 - Book Index

#include <algorithm> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; void Slove(void) { string word; int page; map<string,vector<int> > index; index.clear(); while (cin >> word >> page) { index[word].push_back(page); sort( index[word].begin(),index[word].e…</string,vector<int></vector></string></map></iostream></algorithm>

0104 - Magical Tiles

#include <iostream> #include <string> using namespace std; void Slove(int H, int W) { string figure[H]; bool flg[H][W]; for (int i=0; i<H; ++i) { cin >> figure[i]; for (int j=0; j</h;></string></iostream>

0103 - Baseball Simulation

#include <iostream> #include <string> using namespace std; void Slove(int inning) { int out=0, point=0, count=0; string event; while (inning != 0) { cin >> event; if (event == "HOMERUN") { point+=count+1; count=0; } else if (event == "HIT" ) { if (++count ></string></iostream>…

0102 - Matrix-like Computation

#include <cstdio> #include <iostream> using namespace std; void Slove(int n) { int data[n+1][n+1]; for (int i=0; i<n+1; ++i) for (int j=0; j<n+1; ++j) data[i][j]=0; for (int i=0; i<n; ++i) for (int j=0; j<n; ++j) { cin >> data[i][j]; data[i][n]+=data[i][j]; data[n][j]+=data[i][j]; } for (int j=0; j<…</n+1;></iostream></cstdio>

0101 - Aizu PR

#include <iostream> #include <string> #include <sstream> using namespace std; void Slove(string str_n) { string str; int int_n; stringstream ss; ss << str_n; ss >> int_n; for (int i=0; i</sstream></string></iostream>

0100 - Sale Result

#include <iostream> #include <map> #include <vector> using namespace std; void Slove(int n) { int number; long long price, sale; vector<int> number_data; map<int,long long> money_data; number_data.clear(); money_data.clear(); for (int i=0; i<n; ++i) { cin >> number >> price >> sale; if (!money_dat</n;></int,long></int></vector></map></iostream>…

10033 - Stacking Blocks II

#include <iostream> #include <stack> #include <string> using namespace std; void Slove(int n) { stack<string> st[n]; int p, p1, p2; string op, c; cin >> op; while (op != "quit") { if (op == "push") { cin >> p >> c; st[p-1].push(c); } else if (op == "pop") { cin >> p; cout </string></string></stack></iostream>…

10032 - Stacking Blocks I

#include <iostream> #include <stack> #include <string> using namespace std; void Slove(void) { stack<string> st; string op, word; cin >> op; while (op != "quit") { if (op == "push") { cin >> word; st.push(word); } else if (op == "pop") { cout << st.top() << endl; st.pop()</string></string></stack></iostream>…

10031 - Search II

#include <algorithm> #include <iostream> #include <set> using namespace std; void Slove(int n) { set<int> S; int C=0, number, q, T; for (int i=0; i<n; ++i) { cin >> number; S.insert(number); } cin >> q; for (int i=0; i<q; ++i) { cin >> T; if ( S.find(T) != S.end() ) ++C; } cout << C << endl; } int m…</q;></n;></int></set></iostream></algorithm>

10030 - Search I

#include <algorithm> #include <iostream> #include <set> using namespace std; void Slove(int n) { set<int> S; int C=0, number, q, T; for (int i=0; i<n; ++i) { cin >> number; S.insert(number); } cin >> q; for (int i=0; i<q; ++i) { cin >> T; if ( S.find(T) != S.end() ) ++C; } cout << C << endl; } int m…</q;></n;></int></set></iostream></algorithm>