Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- 백준
- 프로그래머스
- 개발자
- 프로그램
- java정리
- 프로그래밍
- java
- 코딩테스트
- 코딩독학
- Project
- frontend
- 이웃한 칸
- 코테
- 빅데이터
- 주가예측
- 풀스택프레임워크
- 개발
- 코딩
- backend
- C++
- Reflex
- 자바독학
- 사물인터넷
- 모의 주식
- SNS
- 자바
- 개인프로젝트
- 자바정리
- 코스닥
- Python
Archives
- Today
- Total
Creative Code
[17214번]다항 함수의 적분 본문
https://www.acmicpc.net/problem/17214
17214번: 다항 함수의 적분
첫째 줄에 최대 일차 일변수 다항식이 주어진다. 항의 개수는 최대 2개이고, 변수는 항상 x로 주어지며, 각 항은 공백 문자로 구분되지 않는다. 주어지는 계수는 절댓값이 10,000을 넘지 않는 0이
www.acmicpc.net
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
cin >> str;
int a = 0;
int b = 0;
if (str.find('x') != string::npos) {
string str1 = "";
int index = 0;
while (str[index] != 'x') {
str1 += str[index];
index++;
}
a = stoi(str1);
if (str.size() != str.find('x') + 1) {
b = stoi(str.substr(str.find('x') + 1));
}
else {
b = 0;
}
}
else {
a = 0;
b = stoi(str);
}
string s2 = "";
if (b > 0 && a != 0) {
s2 += "+";
}
s2 += to_string(b);
if (a != 0 && b == 1) {
s2 = "+";
}
else if (a != 0 && b == -1) {
s2 = "-";
}
else if (a == 0 && b == 1) {
s2 = "";
}
else if (a == 0 && b == -1) {
s2 = "-";
}
if (a != 0 && a != 2 && a != -2 && b != 0) {
cout << a / 2 << "xx" << s2 << "x+W" << '\n';
}
else if (a != 0 && a != 2 && a != -2 && b == 0) {
cout << a / 2 << "xx+W" << '\n';
}
else if (a == 0 && b != 0) {
cout << s2 << "x+W" << '\n';
}
else if (a == 0 && b == 0) {
cout << "W" << '\n';
}
else if (a == 2 && b != 0) {
cout << "xx" << s2 << "x+W" << '\n';
}
else if (a == 2 && b == 0) {
cout << "xx+W" << '\n';
}
else if (a == -2 && b == 0) {
cout << "-xx+W" << '\n';
}
else if (a == -2 && b != 0) {
cout << "-xx" << s2 << "x+W" << '\n';
}
}
'백준 문제풀이' 카테고리의 다른 글
[2096번]내려가기 (0) | 2023.09.24 |
---|---|
[1107번]리모컨 (0) | 2023.09.24 |
[16496번]큰 수 만들기 (0) | 2023.09.06 |
[7869번]두 원 (0) | 2023.09.05 |
[2981번]검문 (0) | 2023.09.04 |