NOTE/Algorithm

[알고리즘문제] acmicpc_단어의개수

DevAthena 2018. 4. 1. 14:32

https://www.acmicpc.net/problem/1152

집가기전 심심풀이 문제. 

C++ 14 버전으로 냈더니 자꾸 strtok부분에서 에러뜨길래

걍 C++로 냈더니 되네.

버전에 따라 strtok이 strtok_s로 쓰이는건 알고있는데,

strtok_s로 해도 C++14에서 부분에러뜨던데

strtok_s 때문에 헤더를 string.h랑 cstring 넣어도 에러가 떴었고 흠..

이건 어떻게 뭐가 잘못된걸까 (-.-)?


결국 해결된 소스는 걍 C++ 버전의 원래 소스로 낸 아래것

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<iostream>
#include<string.h>
 
#define SIZE 1000001
using namespace std;
 
int main() {
    char arr[SIZE] = { 0, };
    char *token = NULL;
    int count = 0;
 
    cin.getline(arr, sizeof(arr));
 
    token = strtok(arr, " ");
    while (token)
    {
        count++;
        token = strtok(NULL" ");
    }
 
    cout << count << endl;
}
cs