2018年9月13日 星期四

itsa66 3字串切割

#include<iostream>
#include<string>
#include<sstream>
using namespace std;

void replaceD(string &s)
{
int i = 0;
while (i < s.length())
{
if (s[i] == ':' || s[i] == ',' || s[i] == ';')
s[i] = ' ';
i++;
}
}

int main()
{
int N, x = 0;
string s, str[100];
cin >> N;
getline(cin, s);
for (int i = 0; i < N; i++)
{
x = 0;
getline(cin, s);
replaceD(s);
stringstream ss(s);
while (ss >> str[x])
x++;
cout << "Tokens found:\n";
for (int j = 0; j < x; j++)
cout << str[j] << endl;
}
return 0;
}

1 則留言: