落書きノート

ふと自分が気になった事を書いてます

C++で不定期練習 at AIZU ONLINE JUDGE

手始めにイントロダクションからやってみてます。

// Hello World

#include <iostream>

using namespace std;

int main(void) {
  cout << "Hello World" << endl;
  return 0;
}


// Cubic

#include <iostream>

using namespace std;

int main(void) {
  int x;
  cin >> x;
  cout << x * x * x << endl;
  return 0;
}



// Rectangle

#include <iostream>

using namespace std;

int main(void) {
  int a, b;
  cin >> a >> b;
  cout << a * b << ' ' << (a + b) * 2 << endl;
  return 0;
}


// Watch

#include <iostream>

using namespace std;

int main(void) {
  int S;
  int h, m, s;
  cin >> S;
  h = S / 3600;
  S = S % 3600;
  m = S / 60;
  S = S % 60;
  s = S;
  cout << h << ':' << m << ':' << s << endl;
  return 0;
}


// Small Large Equal

#include <iostream>

using namespace std;

int main(void) {
  int a,b;
  cin >> a >> b;
  if(a > b)
    cout << "a > b" << endl;
  else if(a < b)
    cout << "a < b" << endl;
  else
    cout << "a == b" << endl;
  return 0;
}



// Range

#include <iostream>

using namespace std;

int main(void) {
  int a,b,c;
  cin >> a >> b >> c;
  if(a < b && b < c)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


// Sorting Three Numbers

#include <iostream>

using namespace std;

int main(void) {
  int a, b, c;
  cin >> a >> b >> c;
  if(a > b) {
    int t = a;
    a = b;
    b = t;
  }
  if(a > c) {
    int t = a;
    a = c;
    c = t;
  }
  if(b > c) {
    int t = b;
    b = c;
    c = t;
  }
  cout << a << ' ' << b << ' ' << c << endl;
  return 0;
}


// Sorting Three Numbers Another Answer

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

using namespace std;

int main(void) {
  int a, b, c;
  vector<int> v;
  cin >> a >> b >> c;
  v.push_back(a);
  v.push_back(b);
  v.push_back(c);
  sort(v.begin(), v.end());
  cout << v[0] << ' ' << v[1] << ' ' << v[2] << endl;
  return 0;
}