-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
``` |