반응형
https://www.acmicpc.net/problem/9299
9299번: Math Tutoring
For each case, output the line “Case x:” where x is the case number, on a single line. The output polynomial is to be formatted in the same manner as the input: the first value being the highest polynomial, and the successive values being the coefficie
www.acmicpc.net
구현 문제였습니다.
📕 풀이방법
📔 입력 및 초기화
test case 수 t, 가장 큰 지수를 저장할 highestPoly, 한 줄씩 입력받을 변수 str를 선언해줍니다. 이후 적절히 입력해줍니다.
📔 풀이과정
도함수를 구할 때 규칙에 따라 매 지수에 해당하는 계수를 vector ans에 저장해줍니다.
📔 정답출력
형식에 맞게 출력해줍니다.
📕 Code
#include <bits/stdc++.h>
using namespace std;
int t, highestPoly;
string str;
vector <string> split(string input, char delimiter){
vector <string> result;
stringstream ss(input);
string tmp;
while(getline(ss,tmp,delimiter)) result.push_back(tmp);
return result;
}
int main(){
cin >> t;
cin.ignore();
for(int i = 1; i <= t; i++){
getline(cin, str);
vector <string> v = split(str, ' ');
vector <int> ans;
highestPoly = stoi(v[0]);
for(int i = 1; i <= highestPoly; i++){
int num = stoi(v[i]) * (highestPoly - i + 1);
ans.push_back(num);
}
cout << "Case " << i << ": " << highestPoly - 1 << ' ';
for(auto e : ans) cout << e << ' ';
cout << '\n';
}
}
'Algorithm > Implementation' 카테고리의 다른 글
(C++) - 백준(BOJ) 9699 : RICE SACK (0) | 2022.02.25 |
---|---|
(C++) - 백준(BOJ) 9493 : 길면 기차, 기차는 빨라, 빠른 것은 비행기 (0) | 2022.02.24 |
(C++) - 백준(BOJ) 8713 : Znak działania (0) | 2022.02.21 |
(C++) - 백준(BOJ) 9298 : Ant Entrapment (0) | 2022.02.19 |
(C++) - 백준(BOJ) 8815 : Test (2) | 2022.02.18 |