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. Spring Boot 配置加载顺序详解

    使用 Spring Boot 会涉及到各种各样的配置,如开发.测试.线上就至少 3 套配置信息了.Spring Boot 可以轻松的帮助我们使用相同的代码就能使开发.测试.线上环境使用不同的配置. 在 ...

  2. HTML5地理定位API在chrome中不能正常使用

    navigator.geolocation.getCurrentPosition在chrome中不能正常使用. 经测试发现,FQ后就能正常使用,估计是因为chrome 对这个API的实现使用了goog ...

  3. springboot junit

    1 添加pom依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId& ...

  4. python 数据分类赋值

    问题描述:在数据预处理时,往往需要对描述性数据进行分类赋值或对数据进行分级赋值. 首先,会想到用for循环,依次判断赋值: for n in range(len(data1)): print(n) i ...

  5. 【Java】【12】精确的加减乘除运算

    前言:用了BigDecimal对象 正文: 1,加法 /** * @param v1 被加数 * @param v2 加数 * @param scale 保留几位小数*/ public static ...

  6. 移动端跨平台方案对比:React Native、weex、Flutter

    跨平台一直是老生常谈的话题,cordova.ionic.react-native.weex.kotlin-native.flutter等跨平台框架百花齐放,颇有一股推倒原生开发者的势头. 为什么我们需 ...

  7. Kubernetes介绍及基本概念

    kubernetes介绍 Kubernetes是Google在2014年6月开源的一个容器集群管理系统,使用Go语言开发,Kubernetes也叫K8S.K8S是Google内部一个叫Borg的容器集 ...

  8. 生成SQL Server数据字典

    1.表信息 Select * FROM INFORMATION_SCHEMA.COLUMNS order by Table_name; select * from INFORMATION_SCHEMA ...

  9. C++标准模板库(STL)之Map

    1.Map的常用用法 map:映射.可以将任何基本类型,结构体,STL容器映射到任何基本类型包括容器. 使用map,需要加map的头文件,#include<map>和using names ...

  10. python之value和布尔值

    之前做判断的时候如果遇到空列表,空字符串,可以直接使用当做判断条件.比如: s = "" if s: print(s) 不是打印s的,也就在这里if的判断条件是False. 所以, ...