1.环形加密(填空) (5 分)
将26个英文字母按顺时针方向排成一个圆环。密钥是一个整数。
具体加密方法如下:
- 若密钥 key≥0,则从明文字母开始按顺时针方向走 ∣key∣ 步得到密文字母;
- 若密钥 key<0,则从明文字母开始按逆时针方向走 ∣key∣ 步得到密文字母。
下面的程序输入明文和密钥,输出密文。请在空白处填写适当内容完成该程序。
#include <stdio.h> #include <stdio.h> int main() { char plain, secret; int key; scanf(" %c %d", &plain, &key); ____________ printf("%c\n", secret); return 0; }
输入格式
明文(小写字母) 密钥(任意整数)
输出格式
密文(小写字母)
输入样例1
x 5
输出样例1
c
输入样例2
b -3
输出样例2
y
答案:
int x;
key%=26;
plain-='a';
x=(plain+key)%26;
if(x<0)
{
x+=26;
}
secret=x+'a';
2.
计算存款利息-genlib (10 分)
本题要求提交main
函数,实现以下功能:读入存款金额money
、存期year
和年利率rate
,根据下列公式计算存款到期时的利息interest
(税前):
interest=money×(1+rate)year−money
输出时保留2位小数。
注意:你需要提交一个完整的main
函数,但不要修改下列函数提示中已经给出的内容。
函数接口定义及提示:
int main(void) { int money, year; double interest, rate; /*--你需要实现的代码--*/ printf("interest = %.2f\n", interest); return 0; }
裁判测试程序样例:
#include <stdio.h> #include <math.h> #include "genlib.h" #include "simpio.h" /* 你的代码将被嵌在这里 */
输入样例(括号内为说明):
1000 (money = 1000)
3 (year = 3)
0.025 (rate = 0.025)
输出样例:
interest = 76.89
答案:
#include <stdio.h>
#include <math.h>
int main(void)
{
int money, year;
double interest, rate;
scanf("%d/n",&money);
scanf("%d/n",&year);
scanf("%lf",&rate);
double a=1.0+rate;
double z=pow(a,(double)year);
interest=z*money-money;
printf("interest = %.2f\n", interest);
return 0;
}
tips:需换行输入时,可使用多个scanf及\n。