在C ++中,总计n个字母所需的最小字母数。
问题陈述
给定一个整数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
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短