AOJ 0063 Palindrome
#include <iostream> #include <string> using namespace std; bool findPalindrome(string s) { for (int i = 0; i < s.size() / 2; i++) { if (s[i] != s[s.size() - i - 1]) return false; } return true; } int main() { string s; int c = 0; while (cin >> s) { if (findPalindrome(s)) { c++; } } cout << c << endl; return 0; }
AOJ 0062 What is the Bottommost?
なんか上手くいかなかったので文字列に入力してごり押しした
#include <iostream> #include <string> using namespace std; int main() { string n; int a[10]; while (cin >> n) { for (int i = 0; i < 10; i++) a[i] = n[i] - '0'; for (int i = 1; i <= 9; i++) { for (int j = 0; j < 10 - i; j++) { a[j] = (a[j] + a[j + 1]) % 10; } } cout << a[0] << endl; } return 0; }
AOJ 0061 Rank Checker
なんか、頭悪いコード書いたと思う
#include <iostream> #include <vector> #include <algorithm> #include <functional> using namespace std; bool find(vector<int> v, int n) { for (int i = 0; i < v.size(); i++) { if (v[i] == n) return true; } return false; } int main() { int a, b, p[100] = { 0 }; vector<int> v; char t; while (cin >> a >> t >> b) { if (a == 0 && b == 0) break; p[a - 1] = b; if (!find(v, b)) v.push_back(b); } sort(v.begin(), v.end(), greater<int>()); while (cin >> a) { for (int i = 0; i < v.size(); i++) { if (v[i] == p[a - 1]) { cout << i + 1 << endl; break; } } } return 0; }
AOJ 0060 Card Game
残りカードを引いた時の合計が20以下になる場合の数を7.0で割った商が0.5(50%)以上ならYES
#include <iostream> using namespace std; int main() { int c1, c2, c3; while (cin >> c1) { cin >> c2 >> c3; int c[10] = { 0 }, sum = c1 + c2, count = 0; c[c1 - 1] = c[c2 - 1] = c[c3 - 1] = 1; for (int i = 0; i < 10; i++) { if (c[i]) continue; if (sum + i + 1 <= 20) count++; } if (count / 7.0 >= 0.5) cout << "YES"; else cout << "NO"; cout << endl; } return 0; }
AOJ 0059 Intersection of Rectangles
#include <iostream> using namespace std; int main() { double ax, ay, bx, by, cx, cy, dx, dy; while (cin >> ax >> ay >> bx >> by >> cx >> cy >> dx >> dy) { if (ax > dx || bx < cx || ay > dy || by < cy) { cout << "NO"; } else { cout << "YES"; } cout << endl; } return 0; }
AOJ 0058 Orthogonal
内積が0の場合直交している。
#include <cstdio> #include <cmath> using namespace std; #define EPS 1e-10 int main() { double ax, ay, bx, by, cx, cy, dx, dy; while (scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&ax,&ay,&bx,&by,&cx,&cy,&dx,&dy) != EOF) { if (fabs((ax - bx)*(cx - dx) + (ay - by)*(cy - dy)) < EPS) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
AOJ 0057 The Number of Area
n本の線を引いた時の領域の数はn-1本の線を引いた時の数とnの和と等しい
#include <iostream> using namespace std; int main() { int n, a[10001] = { 0 }; a[0] = 1; for (int i = 1; i < 10001; i++) { a[i] = a[i - 1] + i; } while (cin >> n) { cout << a[n] << endl; } return 0; }