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?

More than 1 year has passed since last update.

APG4bで自分が書いたコード2 EX6~10

Last updated at Posted at 2022-07-17

APG4bで自分が書いたコード1の続き
atcoder側からコメントアウトされているソースをコピペして改変して解答することを求められている場合があります。
その場合コメントアウト部分は適宜省略しています

EX6 - 電卓をつくろう

EX6.cpp

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  string op;
  cin >> A >> op >> B;
 if(A>=0&&B<=100)//0≦A,B≦100
 {
  if (op == "+") {
    cout << A + B << endl;}
    
  else  if (op == "-") {
    cout << A - B << endl;}
  
  else if (op == "*") {
    cout << A * B << endl;}
  else if (op == "/"&&B!=0) {
    cout << A / B << endl;}
     else     cout << "error" << endl;
 
 }
  else     cout << "error" << endl;
  }

EX7 - bool値パズル

EX7.cpp
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  // 変数a,b,cにtrueまたはfalseを代入してAtCoderと出力されるようにする。
  bool a = true;// true または false
  bool b = false;// true または false
  bool c =true; // true または false
 
  // ここから先は変更しないこと
 
  if (a) {
    cout << "At";
  }
  else {
    cout << "Yo";
  }
 
  if (!a && b) {
    cout << "Bo";
  }
  else if (!b || c) {
    cout << "Co";
  }
 
  if (a && b && c) {
    cout << "foo!";
  }
  else if (true && false) {
    cout << "yeah!";
  }
  else if (!a || c) {
    cout << "der";
  }
 
  cout << endl;
}


EX8 - たこ焼きセット

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

int main() {
    int p = 0;
    cin >> p;
    int N = 0;
    int price = 0;
    string text;
    if (p == 2 || p == 1) {
        if (p == 2) {
            cin >> text;
        }
        cin >> price;
        cin >> N;
        if (p == 2) {
            cout << text << "!" << endl ;
        }
        cout << price * N << endl;
    }
}

EX9 - 複合代入演算子を使おう

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

int main() {
    int x, a, b;
    cin >> x >> a >> b;
    if (x >= 0 && a <= 100 && b <= 100) {
        // 1.の出力{
        x++;
        cout << x << endl;
        x *= a + b;
        cout << x << endl;

        x *= x;
        cout << x << endl;

        x--;
        cout << x << endl;

   }
}

EX10 - 棒グラフの出力

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

int main() {
	int A, B, i = 0;
	cin >> A >> B;
	if (A >= 0 && A <= 20 && B >= 0 && B <= 20)
		cout << "A:";
	while (i < A)
	{
		cout << "]";
		i++;
	}
	cout << endl;
	i = 0;
	cout << "B:";

	while (i < B)
	{
		cout << "]";
		i++;
	}
	cout << endl;



}

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?