简单问题求解释
题目:令f(a)=1..........f(z)=26f(A)=-1.........f(Z)=-26
输入一个字母和数字
求:
f(字母)+数字的数值;、
#include <stdio.h>
int p(char x1)
{
int y;
if(x1=='a')
y=1;
else
y=p(x1-1)+1;
return y;
}
int f(char x2)
{
int y;
if(x2=='A')
y=-1;
else
y=f(x2-1)-1;
return y;
}
int main()
{
int n,x;
char p1;
while(scanf("%c%d",&p1,&n)!=EOF)
{
if(p1>='a'&&p1<='z')
{x=p(p1)+n;}
else if (p1>='A'&&p1<='Z')
{x=f(p1)+n;}
printf("%d\n",x);
x=0;
}
}