3. 【问题描述】
从键盘输入包含扩展符'-'的字符串,将其扩展为等价的完整字符,例如将a-d扩展为abcd,并输出扩展后的字符串。
要求:只处理[a-z]、[A-Z]、[0-9]范围内的字符扩展,即只有当扩展符前后的字符同时是小写字母、大写字母或数字时才进行扩展,其它情况不进行扩展,原样输出。例如:a-R、D-e、0-b、4-B等字符串都不进行扩展。
【输入形式】
从键盘输入包含扩展符的字符串
【输出形式】
输出扩展后的字符串
【输入样例1】
ADEa-g-m02
【输出样例1】
ADEabcdefghijklm02
【输入样例2】
cdeT-bcd
【输出样例2】
cdeT-bcd
【样例说明】
将样例1的输入ADEa-g-m02扩展为:ADEabcdefghijklm02;样例2的输入cdeT-bcd中,扩展符前的字符为大写字母,扩展符后的字符为小写字母,不在同一范围内,所以不进行扩展。
【评分标准】
结果完全正确得15分,共5个测试点,每个测试点3分,提交程序文件expand.c或expand.cpp。
注意:字符串输入的两种方式
1. 单字符输入
char ch,str[100];
ch=getchar();
while(ch!=' ')
{
str[i]=ch;
ch=getchar();
i++;
}
str[i]=' ';
2. 直接字符串输入
scanf("%s",str);//str以‘ ’结尾
#include <stdio.h> #include <stdlib.h> int getindex(char ch) { int index=-1; if(ch>='a' && ch<='z') index=0; else if(ch>='0' && ch<='9') index=1; else if(ch>='A' && ch<='Z') index=2; return index; } int main() { char str[300],ch;//字符串输入 //ch=getchar(); int i=0,j; /*while(ch!=' ') { str[i]=ch; ch=getchar(); i++; }*/ //str[i]=' ; scanf("%s",str); for(i=0;str[i]!='