Problem A: 重载字符的加减法
Description
定义一个字符类Character,只有一个char类型的数据成员。
重载它的+、-、<<和>>运算符,其中+、-的第二个操作数是int类型的整数n。“+”用于返回以当前字符之后的第n个字符为属性值的对象,“-”用于返回当前字符之前的第n个字符为属性值的对象。如样例所示。
Input
第1行N>0表示测试用例个数。
每个测试用包括1个字符(小写英文字母)和1个int类型的整数。
Output
输出有N行,每行输入对应一行输出,每行输出包括对应输入字符之后的第n个字符,以及该字符之前的第n个字符。如样例中第2个用例输入字符是“a”,整数是“1”,那么“a”之后的第1个字符是”b“,"a"之前的第1个字符是”z“;注意:输入的整数可能是负数。
Sample Input
Sample Output
HINT
Append Code
int main(){ int cases, data; Character ch; cin>>cases; for (int i = 0; i < cases; i++) { cin>>ch; cin>>data; cout<<(ch + data)<<" "<<(ch - data)<<endl; }}using namespace std;
class Character
{
public:char s;
Character(char s = 0):s(s) {}
char operator +(int n)
{
int temp = s+n;
int t;
if(temp > 'z')
t = s+(temp - 'z' -1 )%26;
else if(temp < 'a')
t = 'z' - (s - temp -1)%26;
else
t = temp;
return t;
}
char operator-(int n)
{
return (*this)+(-n);
}
friend ostream & operator <<(ostream &os,Character &c);
friend istream & operator >>(istream &is ,Character &c);
};
ostream & operator <<(ostream &os,Character &c)
{
os<<c.s;
return os;
}
istream & operator >>(istream &is ,Character &c)
{
is>>c.s;
return is;
}
int main()
{
int cases, data;
Character ch;
cin>>cases;
for (int i = 0; i < cases; i++)
{
cin>>ch;
cin>>data;
cout<<(ch + data)<<" "<<(ch - data)<<endl;
}
}
Problem A: 重载字符的加减法的更多相关文章
- 实验12:Problem C: 重载字符的加减法
Home Web Board ProblemSet Standing Status Statistics Problem C: 重载字符的加减法 Problem C: 重载字符的加减法 Time ...
- Problem G: 沉迷字符的WJJ (LCS)
Contest - 河南省多校连萌(四) Problem G: 沉迷字符的WJJ Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 6 Solved: 5 ...
- ZOJ 4010 Neighboring Characters(ZOJ Monthly, March 2018 Problem G,字符串匹配)
题目链接 ZOJ Monthly, March 2018 Problem G 题意 给定一个字符串.现在求一个下标范围$[0, n - 1]$的$01$序列$f$.$f[x] = 1$表示存在一种 ...
- hdu 5427 A problem of sorting(字符排序)
Problem Description There are many people's name and birth in a list.Your task is to print the name ...
- Codeforces Round #253 (Div. 2), problem: (B)【字符串匹配】
简易字符串匹配,题意不难 #include <stdio.h> #include <string.h> #include <math.h> #include < ...
- Problem B: 重载函数:max
Description 编写两个名为max的函数,它们是重载函数 ,用于求两个整数或实数的最大值.它们的原型分别是: int max(int a,int b); double max(double a ...
- Poj(1251),Prim字符的最小生成树
题目链接:http://poj.org/problem?id=1251 字符用%s好了,方便一点. #include <stdio.h> #include <string.h> ...
- HDU 2087 剪花布条(字符串匹配,KMP)
HDU 2087 剪花布条(字符串匹配,KMP) Description 一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出 ...
- HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP)
HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP) Description The French author George ...
随机推荐
- python-request-各方法使用及格式
Request库方法介绍 方法 说明 requests.request() 构造一个请求,支撑一下各方法的基础方法 requests.get() 获取HTML网页的主要方法,对应于HTTP的GET ...
- koa源码之delegate使用
koa中context可以直接调用request和response属性的重要原因是使用了delegate将req和res的属性代理到context, Delegator.prototype.gette ...
- spring boot2.0(二 ) lettcute访问redis
前言 此处已经省略redis的安装,请自行百度查找redis的服务端安装过程. 1.pom文件配置: <project xmlns="http://maven.apache.org/P ...
- PDO设置字符集
<?php header("content-type:text/html;charset=GBK"); class CurlClass { protected $_pdo; ...
- windows 下 修改jmeter ServerAgent端口
from:https://blog.csdn.net/wanglha/article/details/51281462 如果想修改UDP和TCP的端口该如何做呢,可以采用如下的方式: CMD命令进入S ...
- PHP json_decode为什么将json字符串转成数组是对象格式?
eg. $a='[{\"img\":\"/uploads/agency/carimgs/5/15515954778091.jpg\"},{\"img\ ...
- 创建ajax的步骤
第1步:创建XMLHttpRequest对象,也就是创建一个异步调用对象. 第2步:创建一个新的HTTP请求,并指定该HTTP请求的方法.URL以及验证信息. 第3步:设置响应HTTP状态变化的函数. ...
- 基于服务器AAA实验
---恢复内容开始--- 一.实验拓扑 二.实验地址分配 设备 端口 ip 掩码 AAAA g0/0 and se0/3/0 192.168.1.1 and 192.168.4.1 2 ...
- angular 引入ocLazyLoad实现js、controller懒加载
项目之前是直接在index.html中引用了controller.js,其中包含了所有的controller.现引入ocLazyLoad实现按需加载,到指定页面再加载指定js.controller 1 ...
- 利用python解析地址经纬度和利用经纬度定位地址
解析地址经纬度 from geopy.geocoders import Nominatim try: geolocator = Nominatim() location = geolocator.ge ...