Skip to content

Commit

Permalink
Update A-Iroha_and_Haiku.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
AHMEDMOM1 authored Dec 18, 2024
1 parent ef06203 commit 7e7ced1
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions Code Level 1/Atcoder/A-Iroha_and_Haiku.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,66 @@
/*
Problem Statement
Iroha loves Haiku. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.
To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively.
Determine whether she can construct a Haiku by using each of the phrases once, in some order.
Constraints
1≦A,B,C≦10
Input
The input is given from Standard Input in the following format:
A B C
Output
If it is possible to construct a Haiku by using each of the phrases once, print YES (case-sensitive). Otherwise, print NO.
Sample Input 1
5 5 7
Sample Output 1
YES
Using three phrases of length 5, 5 and 7, it is possible to construct a Haiku.
*/

void printResult(bool isHaikuValid) {
cout << (isHaikuValid ? "Yes" : "No");
}

bool isHaikuPattern(short syllableCounts[]) {
short haikuPattern[]{5, 7, 5};
bool isMatched[3]{};
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (!isMatched[j]) {
if (haikuPattern[j] == syllableCounts[i]) {
isMatched[j] = true;
break;
}
}
}
}
for (bool match : isMatched) {
if (!match) {
return false;
}
}
return true;
}

void inputSyllables(short syllableCounts[]) {
for (int i = 0; i < 3; i++) {
do {
cout << "Enter the number of syllables for phrase " << i + 1 << ": ";
cin >> syllableCounts[i];
} while (syllableCounts[i] > 9 || syllableCounts[i] < 1);
}
}

int main() {
short syllableCounts[3]{};
inputSyllables(syllableCounts);
printResult(isHaikuPattern(syllableCounts));
return 0;
}

0 comments on commit 7e7ced1

Please sign in to comment.