結果

問題 No.267 トランプソート
ユーザー cympfh
提出日時 2015-08-22 17:33:32
言語 C++11
(gcc 4.8.5)
結果
AC  
実行時間 26 ms
コード長 2771 Byte
コンパイル時間 2532 ms
使用メモリ 1324 KB

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
sample1.txt AC 6 ms
1320 KB
sample2.txt AC 6 ms
1308 KB
sample3.txt AC 15 ms
1312 KB
test1.txt AC 6 ms
1320 KB
test2.txt AC 6 ms
1316 KB
test3.txt AC 6 ms
1312 KB
test4.txt AC 7 ms
1320 KB
test5.txt AC 26 ms
1312 KB
test6.txt AC 6 ms
1320 KB
test7.txt AC 5 ms
1320 KB
test8.txt AC 6 ms
1320 KB
test9.txt AC 13 ms
1320 KB
test10.txt AC 6 ms
1320 KB
test11.txt AC 4 ms
1324 KB
test12.txt AC 6 ms
1324 KB
test13.txt AC 6 ms
1320 KB
test14.txt AC 6 ms
1324 KB
test15.txt AC 6 ms
1324 KB
test16.txt AC 6 ms
1320 KB
test17.txt AC 6 ms
1320 KB
test18.txt AC 6 ms
1324 KB
test19.txt AC 7 ms
1320 KB
test20.txt AC 6 ms
1320 KB
テストケース一括ダウンロード

ソースコード

diff #
#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define loop for(;;)
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;
#define inf (1e9)
#define eps (1e-9)
using Integer = long long;
using Real = long double;
const Real PI = acosl(-1);

template<class S, class T> inline
ostream& operator<<(ostream&os, pair<S,T> p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template<class S, class T, class U> inline
ostream& operator<<(ostream&os, tuple<S,T,U> t) {
  return os << '('
    << get<0>(t) << ", "
    << get<1>(t) << ", "
    << get<2>(t) << ')';
}

template<class T> inline
ostream& operator<<(ostream&os, set<T> v) {
  os << "(set";
  for (T item: v) os << ' ' << item;
  os << ")";
  return os;
}

template<class T> inline
ostream& operator<<(ostream&os, vector<T> v) {
  if (v.size() == 0) { return os << "(empty)"; }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

template<class T> inline
istream& operator>>(istream&is, vector<T>&v) {
  rep (i, v.size()) is >> v[i];
  return is;
}

enum Suit { D, C, H, S };
struct Card {
  Suit s;
  int n;
  Card() {};
  Card(Suit _s, int _n) : s(_s), n(_n) {};
};

ostream& operator<<(ostream&os, Suit&s) {
  if (s == D) os << 'D';
  else if (s == H) os << 'H';
  else if (s == C) os << 'C';
  else if (s == S) os << 'S';
  else cerr << "Suit show Error" << endl;
  return os;
}

ostream& operator<<(ostream&os, Card&c) {
  os << c.s;
  if (c.n == 1) os << 'A';
  else if (c.n == 10) os << 'T';
  else if (c.n == 11) os << 'J';
  else if (c.n == 12) os << 'Q';
  else if (c.n == 13) os << 'K';
  else os << c.n;
  return os;
}

istream& operator>>(istream&is, Suit&s) {
  char c; is >> c;
  if (c == 'D') s = D;
  else if (c == 'H') s = H;
  else if (c == 'C') s = C;
  else if (c == 'S') s = S;
  else cerr << "Suit read Error" << endl;
  return is;
}

istream& operator>>(istream&is, Card&c) {
  Suit s; is >> s;
  char n; is >> n;
  c.s = s;
  if (n == 'A') c.n = 1;
  else if (n == 'T') c.n = 10;
  else if (n == 'J') c.n = 11;
  else if (n == 'Q') c.n = 12;
  else if (n == 'K') c.n = 13;
  else c.n = n - '0';
  return is;
}

bool operator<(const Card& lh, const Card& rh) {
  if (lh.s != rh.s) return lh.s < rh.s;
  return lh.n < rh.n;
}

//           ^   >  v   <
int dx[] = { -1, 0, 1,  0 };
int dy[] = {  0, 1, 0, -1 };

using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout.setf(ios::fixed);
  cout.precision(10);
  random_device dev;
  mt19937 rand(dev());

  int n; cin >> n;
  vector<Card> cs(n); cin >> cs;
  sort(begin(cs), end(cs));
  cout << cs << endl;

  return 0;
}
0