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 ...
随机推荐
- acm:屁屁上的巴掌
涉及算法:深度搜索 题目: 题目描述 小新是个调皮的孩子,他总是会把衣服搞脏,他的妈妈美伢非常的生气,于是在<和妈妈的约定条款>加上了第三百七十七条:小新衣服上每有一块污渍妈妈就会打小新的 ...
- python语言的基本要素
python语言的基本要素 一.基本的数据类型: 数字类型:整型.浮点型.复数 序列类型:字符串.时间日期 容器类型:列表.元祖.字典(散列表).集合 组合数据类型(容器类型所装载的数据构成数据集合) ...
- DAY 22初识面向对象
一.两种编程思想 1.面向过程编程 核心是'过程',过程指的是解决问题的步骤,就是先干什么再干什么 基于面向过程思想编写程序相当于写一条流水线,是一种机械式的思维方式 优点:解决问题的思路清晰,可以把 ...
- Disable access to Windows Update
Disable access to Windows Update If this policy setting is enabled, all Windows Update features are ...
- python正则表达式 - re
1,匹配符号 任意字符 . : 任意字符,除了\n,flags设置为DOTALL(S)可以让.匹配\n []字符集合,字符组:规范/元字符不同于正则式主体 [0-9] : 数字 [A-Z] : 大写字 ...
- LeetCode--034--在排序数组中查找元素的第一个和最后一个位置(java)
给定一个按照升序排列的整数数组 nums,和一个目标值 target.找出给定目标值在数组中的开始位置和结束位置. 你的算法时间复杂度必须是 O(log n) 级别. 如果数组中不存在目标值,返回 [ ...
- @mentions for Users with ActionText; 使用Tribute.js库
git clone从https://github.com/chentianwei411/at-mentions-with-action-text 先fork下来,然后拷贝https连接,最后在term ...
- Cache Line
转载: https://yq.aliyun.com/articles/46550
- caffe win添加新层
1.编写.h和.cpp .cu文件 将.hpp文件放到路径caffe-windows\caffe-master\include\caffe\layers下 将.cpp文件和.cu放到路径caffe-w ...
- Windos消息驱动
当Window是向程序发送消息时,它调用程序中的一个函数,这个函数用来描述Windows发送的消息,成为窗口函数或消息处理函数.他是一个自定义的回调函数: LRESULT CALLBACK Windo ...