/
UniqueString.cpp
62 lines (56 loc) · 1.06 KB
/
UniqueString.cpp
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
56
57
58
59
60
/*
* File: main.cpp
* Author: Sam
*
* Created on January 16, 2014, 12:46 PM
*/
#include<stdio.h>
#include<iostream.h>
#include <cstdlib>
#include <string>
using namespace std;
/*
*
*/
class HashMap{
private:
int arr[500];
public:
HashMap(){// default constructor
for(int i=0;i<500;i++){
arr[i]=0;
}
}
int getKey(char c){
return (int)c;
}
int atKey(int z){
arr[z]++;
return arr[z];
}
};
bool checkUnique(const char *str, int len, HashMap obj){
if(len>256){
return false;
}
for(int j=0;j<len;j++){
if(obj.atKey(obj.getKey(str[j]))>1){
return false;
}
}
return true;
}
/*int main(int argc, char** argv) {
string str;
HashMap obj;
cout<<"Enter the String to check for unique characters"<<endl;
getline(cin,str);
//cout<<obj.getKey('a')<<endl;
if(checkUnique(str.c_str(),str.length(),obj)){
cout<<"String unique"<<endl;
}else
{
cout<<"String not unique"<<endl;
}
return 0;
}*/