문제 설명
정수 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