夢追い人

"It takes a dreamer to make a dream come true."―Vincent Willem van Gogh

0018~0021

TopCoderレートは644->714でした♪

はやく緑色になりたいなw


今日は練習がてらAOJの楽なものを。

0018

与えられた5つの数字を降順ソート。
STLゲー

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>

using namespace std;

int main() {
	vector<int> num(5);
	cin >> num[0] >> num[1] >> num[2] >> num[3] >> num[4];
	sort(num.begin(), num.end());
	reverse(num.begin(), num.end());
	printf("%d %d %d %d %d\n", num[0],num[1],num[2],num[3],num[4]);
	return 0;
}

0019

与えられた数字の階乗をもとめる。
1<=n<=20なので答えはlong longでないとあふれる。

#include <iostream>
using namespace std;

int main() {
	int n; cin >> n;
	if (n<1) n=1;
	else if (n>20) n=20;
	long long ans=1;
	for (int i=n; i>0; i--) ans *= i;
	cout << ans << endl;
	return 0;
}

0020

与えられた文字を全て大文字にして返す。
入力ではgetlineを使わないとスペース区切りなので最初の単語にしか処理ができない。
※getline(stream, string)・・・指定されたstreamから一行分stringに読み込む

#include <iostream>
#include <string>
#include <cctype>

using namespace std;

int main() {
	string str; getline(cin, str);
	for (int i=0; i<str.length(); i++) {
		if (str[i] != ' ' && str[i] != '.') {
			str[i] = toupper(str[i]);
		}
	}
	cout << str << endl;
	return 0;
}

0021

与えられた座標を結ぶ二つの直線が平行かどうか調べる。
もはや人間でもできる。なぜ問題にしたwww

#include <iostream>

using namespace std;

int main() {
	int n; cin >> n;
	for (int i=0; i<n; i++) {
		double x1,x2,x3,x4,y1,y2,y3,y4;
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
		if ((y2-y1)/(x2-x1) == (y4-y3)/(x4-x3)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

0021とか0017はまぁまぁ手ごわいよ。
それではCodeforces頑張ってきます。