| 网站首页 | 业界新闻 | 群组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
 跟大牛学C++学算法数据结构

已结贴   问题点数：10  回复次数：5

（2=ABC,3=DEF,4=GHI,5=JKL,6=MNO,7=PQRS,8=TUV,9=WXYZ）
Enter phone number:1-800-COL-LECT
In numeric from:1-800-265-5328

Enter a first and last name: Lloyd Fosdick
You enered the name:Fosdick,L

Enter message to be encrypted:  Go ahead,make my day.
Enter shift amount:3
Encrypted message:  Jr dkhdg,pdnh pb gdb.

Enter message to be encrypted:  Jr dkhdg,pdnh pb gdb.
Enter shift amount: 23
Encrypted message:  Go ahead,make my day.

[此贴子已经被作者于2018-4-16 12:36编辑过]

得分:0

得分:1
char ydh[15],xdh[15];
printf("输入一个电话号码\n");
scanf("%s",ydh);
int i,k=0;
for(i=0;ydh[i]!='\0';i++)
switch(ydh[i])
{
case 'A':
case 'B':
case 'C':
xdh[k]='2';
k++;
break;
case 'D':
case 'E':
case 'F':
xdh[k]='3';
k++;
break;
case 'G':
case 'H':
case 'I':
xdh[k]='4';
k++;
break;
case 'J':
case 'K':
case 'L':
xdh[k]='5';
k++;
break;
case 'M':
case 'N':
case 'O':
xdh[k]='6';
k++;
break;
case 'P':
case 'Q':
case 'R':
case 'S':
xdh[k]='7';
k++;
break;
case 'T':
case 'U':
case 'V':
xdh[k]='8';
k++;
break;
case 'W':
case 'X':
case 'Y':
case 'Z':
xdh[k]='9';
k++;
break;
default :
xdh[k]=ydh[i];
k++;
break;
}
xdh[k]='\0';
printf("%s\n",xdh);

得分:0

得分:9

#include <stdio.h>
#include <ctype.h>//用来把小写字母转换成大写字母的库函数
#include <string.h>

int main(void)
{
char str1[15];//存储的数组最大容量
int i, len;

printf ("Enter phone number: ");
gets(str1);//输入一串字符

len = strlen(str1);//测试字符长度
for (i = 0; i < len; i++)
{
str1[i] = toupper(str1[i]);//把小写字母转换成大写字母

switch (str1[i])
{
case 'A':     case 'B':     case 'C':
str1[i] = '2';                break;
case 'D':     case 'E':     case 'F':
str1[i] = '3';                break;
case 'G':     case 'H':     case 'I':
str1[i] = '4';                break;
case 'J':     case 'K':     case 'L':
str1[i] = '5';                break;
case 'M':     case 'N':     case 'O':
str1[i] = '6';                break;
case 'P':     case 'Q':     case 'R':      case 'S':
str1[i] = '7';                break;
case 'T':     case 'U':     case 'V':
str1[i] = '8';                break;
case 'W':     case 'X':     case 'Y' :    case 'Z':
str1[i] = '9';                break;
default :                 str1[i] = str1[i]; break;
}
}
str1[i] = '\0';

printf("In numeric form: %s", str1);

return 0;
}

#include <stdio.h>
#include <string.h>

int main(void)
{
char str[20];
int i, j;
int len, index = 0;

printf ("Enter a first and last name: ");
gets (str);//输入一段字符

len = strlen (str);//测试字符串长度

printf ("You enerad the name: ");
for (i = len - 1; i >= 0; i--)//遍历逆序输出字符
{
if (str[i] == 32)//当输入的字符等于空格的时候就输出空格后面的字符
{
for (j = i + 1; j <= index + i; j++)
{
printf ("%c", str[j]);
}
}
else
index++;//记录索引
}
printf (", %c.", str[0]);//输出第一个字符
printf ("\n");

return 0;

}

#include <stdio.h>
#include <string.h>

int main(void)
{
char str[80], str1[80];
int i, n, len;

printf ("Enter message to be encryted: ");
gets (str);

len = strlen (str);

printf ("Enter shift amount (1-25): ");
scanf ("%d", &n);

for (i = 0; i < len; i++)
{
if (str[i] >= 'A' && str[i] <= 'Z')
{
str1[i] = ((str[i] - 'A') + n) % 26 + 'A';
}
else if (str[i] >= 'a' && str[i] <= 'z')
{
str1[i] = ((str[i] - 'a') + n) % 26 + 'a';
}
else
{
str1[i] = str[i];
}
}

printf ("Encrypted message: ");
for (i = 0; i < len; i++)
{
printf ("%c", str1[i]);
}

return 0;
}
得分:0

• 6
• 1/1页
• 1