[ 문제 ]
[ 접근방법 ]
getline 함수로 줄 단위 입력을 받는다.
istringstream 을 통해 입력받은 string 을 공백을 기준으로 분리한다.
[ 소스코드 ]
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
int n;
void f()
{
string str;
getline(cin, str);
istringstream ss(str);
string stringBuffer;
vector<string> v;
v.clear();
while (getline(ss, stringBuffer, ' '))
{
v.push_back(stringBuffer);
}
double ans = stod(v[0]);
for (int i = 1; i < v.size(); i++)
{
if (v[i] == "@")
{
ans *= 3;
}
if (v[i] == "%")
{
ans += 5;
}
if (v[i] == "#")
{
ans -= 7;
}
}
cout << ans << "\n";
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
cin.ignore();
cout.precision(2);
cout << fixed;
while (n--)
{
f();
}
return 0;
}
'PS' 카테고리의 다른 글
[ 백준 / C++ ] 2491 : 수열 (0) | 2024.05.10 |
---|---|
[ 백준 / C++ ] 19236 : 청소년 상어 (0) | 2024.05.09 |
[ 백준 / C++ ] 17281 : ⚾ (0) | 2024.05.03 |
[ 백준 / C++ ] 1766 : 문제집 (0) | 2024.05.02 |
[ 백준 / C++ ] 2605 : 줄 세우기 (0) | 2024.05.01 |