哈工大 C语言程序设计精髓 MOOC慕课 6-12周编程题答案 下载本文

内容发布更新时间 : 2024/6/1 18:55:59星期一 下面是文章的全部内容请认真阅读。

int main() {

printf(\ char a[80],b[80]; gets(a); if (strlen(a)!=1)

printf(\else{

printf(\ } gets(b);

char *p=strstr(a,b);

if (p){

printf(\ } else{

printf(\ }

return 0; }\

11.4 \/*

题目内容:凯撒密码是罗马扩张时期朱利斯?凯撒(Julius Caesar)创造的,用于加密通过信使传递的作战命令,其原理很简单,就是通过将字母表中的字母移动一定位置而实现加密。例如,每个字母按字母表顺序向后移3位,如a加密后变成d,b加密后变成e,……x加密后变成a,y加密后变成b,z加密后变成c。请编写一个程序,将用户从键盘输入的文本字符串(只包含a~z的字符且长度小于100)进行加密后输出。 函数原型:void Caesar(char c[]) 函数功能:计算凯撒密码 程序的运行结果示例1: Input a string:baidu↙ edlgx

程序的运行结果示例2: Input a string:xyz↙ abc

输入提示信息:\输入格式: 用 gets()函数 输出格式:用 puts()函数 */

#include #include int main()

{

printf(\ char save[2][100]; int a, b, i, j;

gets(save[0]); i=0;b=3;

for (j = 0; j < strlen(save[0]); j++) {

if ((save[i][j] >= 'A' && save[i][j] <= 'Z') || (save[i][j] >= 'a' && save[i][j] <= 'z'))

{

save[i][j] += b;

if (((save[i][j] >= 'A' && save[i][j] <= 'Z') || (save[i][j] >= 'a' && save[i][j] <= 'z')) == 0) {

save[i][j] -= 26; } } }

puts(save[0]);

return (0); }\ 12.1 \/*

用结构体定义时钟类型,编程从键盘任意输入两个时间(例如4时55分和1时25分),计算并输出这两个时间之间的间隔。要求不输出时间差的负号。结构体类型定义如下: typedef struct clock {

int hour; int minute; int second; } CLOCK;

函数原型: CLOCK CalculateTime(CLOCK t1, CLOCK t2); 函数功能:计算并返回两个时间t1和t2之间的差

程序运行结果示例1:

Input time one:(hour,minute):4,55↙ Input time two: (hour,minute):1,25↙ 3hour,30minute 程序运行结果示例2:

Input time one:(hour,minute):1,33↙

Input time two: (hour,minute):5,21↙ 3hour,48minute

输入提示: \,minute):\ \,minute):\输入格式: \

输出格式:\*/

#include

typedef struct Mytime {

int hour; int min; int sec; }T;

int main() {

T t1, t2, t3;

int sec1=0, sec2=0, sec3=0;

printf(\,minute):\