Skip to content

Commit

Permalink
📝 BOJ solution is posted.
Browse files Browse the repository at this point in the history
  • Loading branch information
soo-bak committed Feb 7, 2024
1 parent 8a6f46d commit aaacc15
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions algorithm/boj/_posts/2024-02-08-[APBMC-26].md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
layout: single
title: "[백준 31403] A + B - C (C#, C++) - soo:bak"
date: "2024-02-08 00:15:00 +0900"
description: 수학, 구현, 문자열 등을 주제로 하는 백준 31403번 문제를 C++ C# 으로 풀이 및 해설
---

## 문제 링크
[31403번 - A + B - C](https://www.acmicpc.net/problem/31403)

## 설명
문제의 설명 그대로, `JavaScript` 에서 `+`, `-` 연산자가 '숫자' 와 '문자열' 에 대해서 작동하는 방식을 토대로,<br>
<br>
세 정수 `A`, `B`, `C` 를 입력받아 첫 줄에는 `A`, `B`, `C` 를 '숫자' 로 생각했을 때의 '`A` + `B` - `C`' 의 값을,<br>
<br>
둘 째 줄에는 `A`, `B`, `C` 를 '문자열' 로 생각했을 때의 '`A` + `B` - `C`' 의 값을 출력하는 문제입니다.<br>
<br>

- - -

## Code
<b>[ C# ] </b>
<br>

```c#
namespace Solution {
class Program {
static void Main(string[] args) {

var a = Console.ReadLine()!;
var b = Console.ReadLine()!;
var c = Console.ReadLine()!;

var intRet = int.Parse(a) + int.Parse(b) - int.Parse(c);
var strRet = int.Parse(a + b) - int.Parse(c);

Console.WriteLine(intRet);
Console.WriteLine(strRet);
}
}
}
```
<br><br>
<b>[ C++ ] </b>
<br>

```c++
#include <bits/stdc++.h>

using namespace std;

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);

int a, b, c; cin >> a >> b >> c;

cout << a + b - c << "\n";

string strA = to_string(a);
string strB = to_string(b);
string strC = to_string(c);

int resultStr = stoi(strA + strB) - stoi(strC);
cout << resultStr << "\n";

return 0;
}
```

0 comments on commit aaacc15

Please sign in to comment.