-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path112A.cpp
82 lines (48 loc) · 1.37 KB
/
112A.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cctype>
/*
Notes:
Approach : Optimsed
Use ASCII.
Use a while loop and compare strings by each char.
If either is uppercase, change to lower and redo loop.
Exit loop early if found a result.
Debug:
*/
int main() {
std::string s1, s2;
std::cin >> s1 >> s2;
int index = 0;
while(index < s1.length()) {
if(std::isupper(s1[index])) s1[index] = std::tolower(s1[index]);
if(std::isupper(s2[index])) s2[index] = std::tolower(s2[index]);
if(s1[index] < s2[index]) {
std::cout << -1 << std::endl;
return 0;
}
else if(s2[index] < s1[index]) {
std::cout << 1 << std::endl;
return 0;
}
++index;
}
std::cout << 0 << std::endl;
return 0;
}
/* Slow Solution
int main() {
std::string s1, s2;
std::cin >> s1 >> s2;
std::transform(s1.begin(), s1.end(), s1.begin(),
[](unsigned char c){ return std::tolower(c); });
std::transform(s2.begin(), s2.end(), s2.begin(),
[](unsigned char c){ return std::tolower(c); });
if(s1 < s2) std::cout << -1 << std::endl;
else if(s2 < s1) std::cout << 1 << std::endl;
else std::cout << 0 << std::endl;
return 0;
}
*/