zoukankan      html  css  js  c++  java
  • 杭电oj An easy problem

    </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
    ",sum);
    	}
    	return 0;
    }
    
    

  • 相关阅读:
    vs2010在进行数据架构比较时报'text lines should not be null'错误
    idea安装2019
    无法获得VMCI驱动程序的版本:句柄无效
    VMware对虚拟机快照进行克隆
    此主机支持Intel VT-x,但Intel VT-x处于禁用状态
    惠普台式机,如何开启虚拟化技术
    eclipse格式化代码快捷键失效
    python之shutil模块
    hadoop中hive常用的交互式操作
    hadoop中hive的属性
  • 原文地址:https://www.cnblogs.com/NYNU-ACM/p/4236796.html
Copyright © 2011-2022 走看看