समस्या कथन
एक पूर्णांक n दिया गया है और a =1, b =2, c =3, ….., z =26 दें। कार्य कुल n बनाने के लिए आवश्यक अक्षरों की न्यूनतम संख्या ज्ञात करना है
If n = 23 then output is 1 If n = 72 then output is 3(26 + 26 + 20)
एल्गोरिदम
1. If n is divisible by 26 then answer is (n/26) 2. If n is not divisible by 26 then answer is (n/26) + 1
उदाहरण
#include <iostream>
using namespace std;
int minRequiredSets(int n){
if (n % 26 == 0) {
return (n / 26);
} else {
return (n / 26) + 1;
}
}
int main(){
int n = 72;
cout << "Minimum required sets: " << minRequiredSets(n) << endl;
return 0;
} आउटपुट
जब आप उपरोक्त प्रोग्राम को संकलित और निष्पादित करते हैं। यह निम्न आउटपुट उत्पन्न करता है -
Minimum required sets: 3