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

3 a 0 a 1 a -1

Sample Output

a a b z z b

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;
    }
}
 
 
代码
#include<iostream>
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: 重载字符的加减法的更多相关文章

  1. 实验12:Problem C: 重载字符的加减法

    Home Web Board ProblemSet Standing Status Statistics   Problem C: 重载字符的加减法 Problem C: 重载字符的加减法 Time ...

  2. Problem G: 沉迷字符的WJJ (LCS)

    Contest - 河南省多校连萌(四) Problem G: 沉迷字符的WJJ Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 6  Solved: 5 ...

  3. ZOJ 4010 Neighboring Characters(ZOJ Monthly, March 2018 Problem G,字符串匹配)

    题目链接  ZOJ Monthly, March 2018 Problem G 题意  给定一个字符串.现在求一个下标范围$[0, n - 1]$的$01$序列$f$.$f[x] = 1$表示存在一种 ...

  4. 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 ...

  5. Codeforces Round #253 (Div. 2), problem: (B)【字符串匹配】

    简易字符串匹配,题意不难 #include <stdio.h> #include <string.h> #include <math.h> #include < ...

  6. Problem B: 重载函数:max

    Description 编写两个名为max的函数,它们是重载函数 ,用于求两个整数或实数的最大值.它们的原型分别是: int max(int a,int b); double max(double a ...

  7. Poj(1251),Prim字符的最小生成树

    题目链接:http://poj.org/problem?id=1251 字符用%s好了,方便一点. #include <stdio.h> #include <string.h> ...

  8. HDU 2087 剪花布条(字符串匹配,KMP)

    HDU 2087 剪花布条(字符串匹配,KMP) Description 一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出 ...

  9. 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 ...

随机推荐

  1. ios高级开发之多线程(二)NSThread技术

    多线程技术是有多套解决方案的,那么我们该如何选择呢? 技术方案 简介 语言 线程生命周期 使用频率 pthread 1.一套通用的多线程API 2.适用于UNIX,linux,windows等 3.跨 ...

  2. web.xml 设置字符编码

    个人理解  就是为了防止在前端输入的数据到了后台发生乱码 直接复制到web.xml里面就可以使用 亲测 能用!!! <!-- 前端过滤器设置字符编码 --> <filter> ...

  3. expect免互交 常用编辑文本

    expect免互交 yum -y install expect cat ip_pass.txt #这里写上要执行的IP地址和root用户密码 cat ssh2.exp #编写要执行的操作 #!/usr ...

  4. ZooKeeper如何完成分布式锁?

    * 面试答案为LZ所写,如需转载请注明出处,谢谢. 1.最基本的思路: 将<local_ip>:<task_id>存在某个路径节点里. 刚开始并没有这个节点,当有executo ...

  5. NodeJS基础总结(一)

    NodeJS官网网址:https://nodejs.org/en/ 使用require方法加载fs核心模块 var fs = require('fs'); 一.读取文件//   第一个参数就是尧读取的 ...

  6. 解决安卓JNI native 线程不能正常退出问题二

    直面这个解决方法的可以看我转载的博客            https://www.cnblogs.com/Carlsblog/p/9438016.html 本方法是个投机取巧法,不过也解决了不能正常 ...

  7. 微信小程序 页面跳转方式

    // 保留当前页面,跳转到应用内的某个页面,使用wx.navigateBack可以返回到原页面. // 注意:调用 navigateTo 跳转时,调用该方法的页面会被加入堆栈,但是 redirectT ...

  8. 从零开始学Python 三(网络爬虫)

    本章由网络爬虫的编写来学习python.首先写几行代码抓取百度首页,提提精神,代码如下: import urllib.request file=urllib.request.urlopen(" ...

  9. request.getParameter()在get和post方法中文乱码问题

    乱码原因:Http请求传输时将url以ISO-8859-1编码,服务器收到字节流后默认会以ISO-8859-1编码来解码成字符流(造成中文乱码) post请求: 假设提交请求的jsp页面是UTF-8编 ...

  10. windows重叠I/O模型

    重叠I/O就相当于异步I/O. 一.重叠I/O的I/O完成确认 1.使用事件对象 接收端: #include <stdio.h> #include <stdlib.h> #in ...