-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisogram.cpp
More file actions
72 lines (49 loc) · 1.19 KB
/
isogram.cpp
File metadata and controls
72 lines (49 loc) · 1.19 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
/*
isogram.cpp
arataca89@gmail.com
Aulas de programação em C++
CodeWars exercise:
An isogram is a word that has no repeating letters, consecutive or
non-consecutive. Implement a function that determines whether a
string that contains only letters is an isogram.
Assume the empty string is an isogram. Ignore letter case.
isIsogram "Dermatoglyphics" == true
isIsogram "aba" == false
isIsogram "moOse" == false -- ignore letter case
*/
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <string>
using std::string;
bool is_isogram(std::string str);
int main(){
bool b;
//b = is_isogram("");
b = is_isogram("Dermatoglyphics");
//b = is_isogram("aba");
//b = is_isogram("moOse");
cout << (b?"True":"False") << endl;
return 0;
}
bool is_isogram(std::string str) {
if(!str.length()) return false;
char c;
int i,j;
int size = str.length();
char buff[size];
for(int i=0;i<size;i++)
buff[i] = str[i];
for(int i=0;i<size-1;i++)
buff[i] = tolower(buff[i]);
for(i=0;i<size-1;i++){
c = buff[i];
for(j=i+1;j<size;j++){
if(c == buff[j])
return false;
}
}
return true;
}
// end of isogram.cpp