问题及代码:
/*
* Copyright (c) 2014, 烟台大学计算机学院
* All rights reserved.
* 文件名称:test.cpp
* 作 者:刘佳琦
* 完成日期:2014年 11 月 2 日
* 版 本 号:v1.0
*
* 问题描述:解读密码M$pszi$y
* 输入描述:输入M$pszi$y
* 程序输出: 密码的答案
*/
#include<iostream>
#include <cstdio>
using namespace std;
int main()
{
char ch;
int x;
while((ch=getchar())!='\n')
{
putchar(ch-x);
}
return 0;
}
运行结果:
/*
* Copyright (c) 2014, 烟台大学计算机学院
* All rights reserved.
* 文件名称:test.cpp
* 作 者:刘佳琦
* 完成日期:2014年 11 月 2 日
* 版 本 号:v1.0
*
* 问题描述:解读密码M$pszi$y
* 输入描述:输入M$pszi$y
* 程序输出: 密码的答案
*/
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int x;
char ch;
cin>>x;
getchar(); //getchar接受前面输入x后的回车,解释见博客getchar初运用
while((ch=getchar())!='\n')
{
putchar(ch-x);
}
return 0;
}
运行结果:
知识点总结:领会getcher的运用
学习心得:很有意思的一次程序,慢慢在程序中找到乐趣,越来越喜欢啦!