杭电oj An easy problem

时间:2023-03-08 16:43:08
</pre><h1 style="color: rgb(26, 92, 200);">An easy problem</h1><strong><span style="color: green; font-family: Arial;">Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 14028    Accepted Submission(s): 9462</span></strong><div align="left" class="panel_title">Problem Description</div><div class="panel_content">we define f(A) = 1, f(a) = -1, f(B) = 2, f(b) = -2, ... f(Z) = 26, f(z) = -26;Give you a letter x and a number y , you should output the result of y+f(x).</div><div class="panel_bottom"> </div><div align="left" class="panel_title">Input</div><div class="panel_content">On the first line, contains a number T.then T lines follow, each line is a case.each case contains a letter and a number.</div><div class="panel_bottom"> </div><div align="left" class="panel_title">Output</div><div class="panel_content">for each case, you should the result of y+f(x) on a line.</div><div class="panel_bottom"> </div><div align="left" class="panel_title">Sample Input</div><div class="panel_content"><pre><div style="font-family: Courier New,Courier,monospace;">6
R 1
P 2
G 3
r 1
p 2
g 3</div>
Sample Output
19
18
10
-17
-14
-4
Author
8600
Source

我的代码://可能不是最优。。也可能很简单。。先判断输入的字符的大写的还是小写的,然后对应的数和输入的数字相加。。
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
int T,i;
char x;
double y,sum;
cin>>T;
while(T--)
{
cin>>x>>y;
if(x>='A'&&x<='Z')
{
for(i=0;i<26;i++)
{
if(x=='A'+i)
{
sum=i+1+y;
break;
}
}
}
if(x>='a'&&x<='z')
{
for(i=0;i<26;i++)
{
if(x=='a'+i)
{
sum=-i-1+y;
break;
}
}
}
printf("%.0lf\n",sum);
}
return 0;
}