该问题需要按照以下规则输出输入:
1. if the input character is between A-Z, or a-z, the out put character would be
the following letter, abc-->bcd
2. if the input is Z or z, the output would be A or a, z->a,Z->A
3. if the input is space, then it remains the same
4. if the input is anything else, increment its ascii value by 1, and print.这就是一个例子:
input: abcZ ]
output: bcdA ^这是我的代码:
#include <iostream>
using namespace std;
int main()
{//use ASCII to get a code for input by changing a to b, b to c....z to a, space remain the same, everything else ++
char c,d;
int i=0;
for(i=0;;i++)
{
if (('A' <= (c=cin.get()) < 'Z')||('a' <= (c=cin.get()) < 'z'))
{
d=c+1;
}
else if(c=cin.get()==32)// ascii value of space is 32
d=c;
else if((c=cin.get())=='Z')
d='A';
else if((c=cin.get())=='z')
d='a';
else
{
c++;
d=c;
}
cout<<d;
}
cout<<endl;
return 0;
}这是输出:

我想的是♂是enter键的输出,但是我不想要enter键的输出。空格,Z和z也不能正确地转换。
有人能帮我处理密码吗?谢谢。
发布于 2014-02-05 01:54:14
你这里有一大堆问题。以下是一些提示:
1)每次循环迭代只调用一次cin.get()。这就是:
for (...)
{
c = cin.get();
// do not call cin.get() beyond this point.
// use the c variable instead
...
}2)注意你的复合条件。
而不是:('A' <= c < 'Z'),您真的想要:('A' <= c && c < 'Z')
3)添加另一个条件以检查10。这是行提要字符的代码。如果检测到这一点,只需执行cout << endl
这里也有许多简化逻辑的方法。继续努力!
https://stackoverflow.com/questions/21567026
复制相似问题