-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiffIntInStr.cpp
More file actions
46 lines (41 loc) · 906 Bytes
/
Copy pathdiffIntInStr.cpp
File metadata and controls
46 lines (41 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <bits/stdc++.h>
using namespace std;
// Number of Different Integers in a String
class Solution
{
bool isDigit(char c)
{
return (c >= '0' && c <= '9');
}
public:
int numDifferentIntegers(string word)
{
string num = "";
set<string> nums;
for (int i = 0; i < word.size(); i++)
{
if (isDigit(word[i]))
{
if (num == "0")
num = "";
num += word[i];
// cout << num << " ";
}
else if (num != "")
{
nums.insert(num);
// cout << num << " ";
num = "";
}
}
if (isDigit(word.back()))
nums.insert(num);
return nums.size();
}
};
int main()
{
string s;
cin >> s;
cout << Solution().numDifferentIntegers(s);
}