#40638: C++ (AC)


1121228@stu.wghs.tp.edu.tw (jhhc)

學校 : 臺北市私立薇閣高級中學
編號 : 266561
來源 : [60.248.154.139]
最後登入時間 :
2024-11-11 12:54:12
d487. Order's computation process -- 學姊 | From: [60.248.154.143] | 發表日期 : 2024-06-03 11:52

#include <iostream>
using namespace std;
int main() {
  int a;
  while (cin >> a) {
    if (a!=0){
      int i = a;
      int t = a;
      if (a == 1) {
        cout << a << "! = ";
      } else if (a > 1) {
        cout << a << "! = " << a << " * ";
      } 
      while (i-- && i > 1) {
        cout << i << " * ";
      }
      if (t != 0) {
        cout << 1 << " = ";
      }
      for (int q = 1; q < a; q++) {
        t = t * q;
      }
      cout << t << endl;
    }
    else {
      cout << "0! = 1 = 1" << endl;
    }
  }
}

 
ZeroJudge Forum