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 ...
随机推荐
- CopyOnWriteArrayList与Collections.synchronizedList的性能对比(转)
列表实现有ArrayList.Vector.CopyOnWriteArrayList.Collections.synchronizedList(list)四种方式. 1 ArrayList Array ...
- 基于python的Splash基本使用和负载均衡配置
0.引言 由于在软件工程综合实践专题课程中,老师要求在博客园发表博客我自己做过的小项目,本博客为课程第一篇博客 本项目来源于寒假学习python网络爬虫时所做的实战小项目,经过精心挑选,选择了页面动态 ...
- springcloud采坑--Zuul上传文件报java.nio.charset.IllegalCharsetNameException: UTF-8;boundary=sqgzzmMxl1UPdIp0IAYnQgUIAr9yNewVAzKIX
报错日志: 2018-12-17 10:01:19,688 ERROR [io.undertow.request] (default task-3) UT005023: Exception handl ...
- python学习之读写csv文件(使用pandas)
简介 逗号分隔值(Comma-Separated Values,CSV,有时也称为字符分隔值,因为分隔字符也可以不是逗号),其文件以纯文本形式存储表格数据(数字和文本).纯文本意味着该文件是一个字符序 ...
- ArcGIS发布地图服务时报错Error: ArcGIS Server site is currently being configured by another administrative operation. Please try again later.
2017-06-06试图发布ArcGIS Server站点托管的服务时,返回以下错误消息: ERROR: Service 'test'.'MapServer' in folder '/' is cur ...
- redis 高可用
Redis-Sentinel是Redis官方推荐的高可用性(HA)解决方案,当用Redis做Master-slave的高可用方案时,假如master宕机了,Redis本身(包括它的很多客户端)都没有实 ...
- W10激活
1.首先,我们先查看一下Win10正式专业版系统的激活状态: 点击桌面左下角的“Windows”按钮,从打开的扩展面板中依次点击“设置”-“更新和安全”,并切换到“激活”选项卡,在此就可以查看到当前系 ...
- 微信跳转外部浏览器下载app
很多朋友问我怎么解决微信内点击链接或扫描二维码可以直接跳出微信在外部浏览器打开网页链接和下载APP,其实这并不难,只要我们实现微信跳转功能即可.下面给大家介绍这个功能 方案实现教程:http://sk ...
- MACE移植要求
MACE支持Tensorflow的depth_to_space和space_to_depth,以及strided_slice算子. 其中depth_to_space可以用来无平滑地进行上采样. spa ...
- css--nth-child的注意点
nth-child( n ) 里面的n可以是任何整数值. 不过要取第一位开始的元素DOM对象,那么n是从1开始的 如果n值小于0或者等于0,是不会匹配任何元素,(或者超过数量)切记切记!!!! 例子: ...