全文预览

C程题目答案

上传者:相惜 |  格式:doc  |  页数:15 |  大小:50KB

文档介绍
terreplaced:1+2=3思路:A-Z,B-Y,...Z-A,左右字符的ASCII值的和都是一样的,都为'A'+'Z',设左字符为变量x,右字符的ASCII值就是'A'+'Z'-x#include"stdio.h"#include"string.h"#defineMAXLEN80intmain(void){charch;charstr[MAXLEN];inti;intrepeat,ri;scanf("%d",&repeat);getchar();for(ri=1;ri<=repeat;ri++){i=0;while((ch=getchar())!='\n'){str[i]=ch;i++;}str[i]=0;for(i=0;str[i]!=0;i++){if(str[i]>='A'&&str[i]<='Z')str[i]='A'+'Z'-str[i];}printf("Afterreplaced:");for(i=0;str[i]!=0;i++)putchar(str[i]);putchar('\n');}}70035将十六进制字符串转换为十进制整数输入一个正整数repeat(0<repeat<10),做repeat次下列运算:输入一个以回车结束的字符串(少于80个字符),滤去所有的非十六进制字符后,组成一个新字符串(十六进制形式),然后将其转换为十进制数后输出。输入输出示例:括号内为说明输入:2(repeat=2)10+A输出:Dec=16Dec=10#include"stdio.h"#include"string.h"#defineMAXLEN80intmain(void){charch;charstr[MAXLEN],num[MAXLEN];inti,k;intrepeat,ri;longnumber;scanf("%d",&repeat);getchar();

收藏

分享

举报
下载此文档