-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstringDuplicates.cpp
More file actions
55 lines (42 loc) · 864 Bytes
/
stringDuplicates.cpp
File metadata and controls
55 lines (42 loc) · 864 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
47
48
49
50
51
52
53
54
55
#include <iostream>
using namespace std;
//Basic Program
/*
int main(int argc, char const *argv[])
{
char arr[]="aaabbbbccdddeffghi";
int count =0;
for(int i=0;arr[i]!='\0';i++){
for(int j=i+1;arr[j]!='\0';j++){
if(arr[i]==arr[j]){
count++;
cout << arr[i]<<" --->" << count << endl;
break;
}
}
}
return 0;
}*/
// Changes the Logic
const int NO_OF_CHAR=256;
void printDup(string s){
int count[NO_OF_CHAR]={};
for(int i=0;i<s.size();i++){
cout<<"Value is "<< count[s[i]] << endl;
count[s[i]]++;
cout<<"Value is after Increment " << count[s[i]] << endl;
}
for(int i=0;i<s.size();i++){
if(count[s[i]]>1){
cout<< s[i] << " count = "<<count[s[i]]<<endl;
count[s[i]]=0;
}
}
}
int main(int argc, char const *argv[])
{
string s= "hello world";
cout<<"Size is "<<s.size()<<endl;
printDup(s);
return 0;
}