0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

C++入門 AtCoder Programming Guide for beginners (APG4b) 備忘録

Last updated at Posted at 2024-06-01

EX8 - たこ焼きセット

自分で書いたプログラム

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

int main() {
  int p;
  cin >> p;

  // パターン1
  if (p == 1) {
    int price;
    int N;
    cin >> price >> N;
    cout << price * N << endl;
  }

  // パターン2
  if (p == 2) {
    string text;
    int price;
    int N;
    cin >> text >> price >> N;
    cout << text << "!" << endl;
    cout << price * N << endl;
  }
}

模範解答

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

int main() {
  int p;
  cin >> p;

  // パターン2
  if (p == 2) {
    string text;
    cin >> text;
    cout << text << "!" << endl;
  }

  int price, N;
  cin >> price >> N;
  cout << price * N << endl;
}

気づいたこと
・P==1,P==2の場合で、それぞれコードを書いたが、模範解答では、P==2の場合に出力結果が変わるように表現されている。
・複数のint型の変数を定義する際に、私はint price; int N;と2行で表現したが、模範解答ではint price, N と1行で表現している。

・chatgptにレビューさせる

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?