結果

問題 No.2765 Cross Product
ユーザー tnakao0123
提出日時 2024-06-01 11:37:50
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,355 bytes
コンパイル時間 642 ms
コンパイル使用メモリ 40,320 KB
最終ジャッジ日時 2025-02-21 18:59:58
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void readpt(pt3d&)’:
main.cpp:51:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   51 | void readpt(pt3d &p) { scanf("%d%d%d", &p.x, &p.y, &p.z); }
      |                        ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2765.cc:  No.2765 Cross Product - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

/* typedef */

template <typename T>
struct Pt3d {
  T x, y, z;

  Pt3d() {}
  Pt3d(T _x, T _y, T _z) : x(_x), y(_y), z(_z) {}
  Pt3d(const Pt3d& pt) : x(pt.x), y(pt.y), z(pt.z) {}

  bool operator==(const Pt3d pt) const {
    return x == pt.x && y == pt.y && z == pt.z;
  }
  Pt3d<T> operator+(const Pt3d pt) const {
    return Pt3d<T>(x + pt.x, y + pt.y, z + pt.z);
  }
  Pt3d<T> operator-() const {
    return Pt3d<T>(-x, -y, -z);
  }
  Pt3d<T> operator-(const Pt3d pt) const {
    return Pt3d<T>(x - pt.x, y - pt.y, z - pt.z);
  }
  Pt3d<T> operator*(T t) const {
    return Pt3d<T>(x * t, y * t, z * t);
  }
  Pt3d<T> operator/(T t) const {
    return Pt3d<T>(x / t, y / t, z / t);
  }
  T dot(Pt3d v) const { return x * v.x + y * v.y + z * v.z; }
  Pt3d<T> cross(Pt3d v) const {
    return Pt3d<T>(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
  }
};

typedef Pt3d<int> pt3d;

/* subroutines */

void readpt(pt3d &p) { scanf("%d%d%d", &p.x, &p.y, &p.z); }
void printpt(pt3d &p) { printf("%d %d %d\n", p.x, p.y, p.z); }

/* global variables */

/* subroutines */

/* main */

int main() {
  pt3d a, b;
  readpt(a), readpt(b);

  pt3d c = a.cross(b);
  printpt(c);
  
  return 0;
}
0