-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpermutation.cpp
More file actions
38 lines (33 loc) · 808 Bytes
/
permutation.cpp
File metadata and controls
38 lines (33 loc) · 808 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
#include <iostream>
using namespace std;
bool isPermutation(char input1[], char input2[]);
int main() {
char input1[100];
char input2[100];
cin >> input1 >> input2;
bool result = isPermutation(input1, input2);
cout << result << endl;
return 0;
}
bool isPermutation(char input1[], char input2[]) {
int finalSum = 0;
bool one = false, two = false;
for (int i = 0;; i++) {
// cout << i << " " << input1[i] << " " << input2[i] << endl;
if (input1[i] == '\0') {
one = true;
}
if (input2[i] == '\0') {
two = true;
}
if (one && two) {
break;
}
finalSum += input1[i] - input2[i];
}
if (finalSum == 0) {
return true;
} else {
return false;
}
}