hdoj-2055-An easy problem
2016-05-26 16:20
423 查看
[align=left]Problem Description[/align]
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).
[align=left]Input[/align]
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.
[align=left]Output[/align]
for each case, you should the result of y+f(x) on a line.
[align=left]Sample Input[/align]
6
R 1
P 2
G 3
r 1
p 2
g 3
[align=left]Sample Output[/align]
19
18
10
-17
-14
-4
上AI实验课闲来无事随便找了一题写的
sabi题不解释
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<map>
using namespace std;
map<char,int>a[60];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
char c;
int n;
int sum=0;
getchar();
scanf("%c",&c);
scanf("%d",&n);
if(c>='A'&&c<='Z') sum=c-'A'+1;
else if(c>='a'&&c<='z') sum=(c-'a'+1)*(-1);
sum+=n;
printf("%d\n",sum);
}
return 0;
}
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).
[align=left]Input[/align]
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.
[align=left]Output[/align]
for each case, you should the result of y+f(x) on a line.
[align=left]Sample Input[/align]
6
R 1
P 2
G 3
r 1
p 2
g 3
[align=left]Sample Output[/align]
19
18
10
-17
-14
-4
上AI实验课闲来无事随便找了一题写的
sabi题不解释
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<map>
using namespace std;
map<char,int>a[60];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
char c;
int n;
int sum=0;
getchar();
scanf("%c",&c);
scanf("%d",&n);
if(c>='A'&&c<='Z') sum=c-'A'+1;
else if(c>='a'&&c<='z') sum=(c-'a'+1)*(-1);
sum+=n;
printf("%d\n",sum);
}
return 0;
}
相关文章推荐
- java责任链模式1
- 作为前端应当了解的Web缓存知识
- 变量类型
- 工作流引擎Oozie(一):workflow
- mysql 备份 rsync
- CentOS6.5基本命令汇总
- Spring Security(18)——Jsp标签
- 数据库基本操作
- Spring Security(17)——基于方法的权限控制
- 【Zookeeper源码二】Zookeeper 客户端创建连接过程分析
- Android优化列表的卡顿现象
- Android架构学习MVC、MVP、MVVM(二)
- 'hibernateTemplate' must be of type [org.springframework.orm.hibernate5.HibernateTemplate]
- android log丢失(一)使用logd丢失log原理
- Nginx,原生PHP 搭建小型web app
- 中文路径, 文件转换
- 如何将pdf转换成txt格式
- xml之DOM方式解析,DOM4J工具解析原理
- 切换后台tomcat
- InitializeCriticalSection