숫자의 개수가 아니라 콤마의 개수를 센 다음 1을 더해주면 간단히 해결할 수 있다.
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <bitset>
#define xx first
#define yy second
#define all(x) (x).begin(), (x).end()
using namespace std;
using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
int main()
{
string str;
cin >> str;
int ans = 1;
for (int i = 0; i < str.size(); i++)
{
if (str[i] == ',')
ans++;
}
cout << ans << endl;
return 0;
}
'백준' 카테고리의 다른 글
10814 나이순 정렬 (0) | 2020.09.21 |
---|---|
11564 점프왕 최준민 (0) | 2020.09.21 |
1107 리모컨 [미완] (0) | 2020.09.20 |
15900 나무 탈출 (0) | 2020.09.20 |
14923 미로 탈출 (0) | 2020.09.20 |