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 ...
随机推荐
- 在微信浏览器中 location.reload() 不刷新解决方案(直接调用方法)
1.问题 在微信浏览器中,需要时刷新当前页面. 正常情况下我们直接使用 location.reload 方法来刷新. 2.解决方法 function realod(){ var {search,hre ...
- lua 5.3.5 安装/初体验
安装 官网http://www.lua.org/start.html 参考 https://blog.csdn.net/qq_23954569/article/details/70879672 cd ...
- deep learning的一些知识点
softmax loss: softmax: softmax的作用,将fc的输出映射成为(0,1)的概率,并将其差距拉大. cross entropy loss: y是样本的真实标签,为1 ...
- python-json函数
json函数使用 JSON 函数需要导入 json 库:import jsonjson函数包含:json.dumps,json.loads,json.load,json.dump #1.json.du ...
- newcoder-最长树链-树/gcd
https://ac.nowcoder.com/acm/problem/13233 链接:https://ac.nowcoder.com/acm/problem/13233来源:牛客网 题目描述 树链 ...
- Linuxpython3安装库
- leetcode 230 二叉搜索树中第K小的元素
方法1:统计每个节点的子节点数目,当k>左子树节点数目时向左子树搜索,k=左子树节点数目时返回根节点,否则向右子树搜索. 方法2:递归中序遍历,这里开了O(n)空间的数组. class Solu ...
- WPF中定时器与进度条的配合使用
WPF中定时器使用的注意事项: WPF需要使用System.Windows.Threading.DispatcherTimer定时器,而不能使用System.Timers.Timer定时器.因为Sys ...
- php上传文件,接口是java,go。
$uri = ‘https://www.xxx.com/api/xxxxx’; $ch = curl_init(); //加@符号curl就会把它当成是文件上传处理 $tmpName = $_FILE ...
- windows下Xshell远程访问虚拟机
下载Xshell 5软件在windows下安装 安装好后Xshell 5启动软件 下一步,检查虚拟机,配置是否正确 下一步,设置网络,保障虚拟机系统能够连接网络 下一步,进入虚拟机系统,检查虚拟机网络 ...