为啥不对啊,答案是对的但就是0分,有人能帮个忙吗

P1914 小书童——凯撒密码

Driver0309 @ 2019-09-07 13:32:22

#include<iostream>
#include<cstring>
#include <cstdio>
using namespace std;

int main()
{
    char a[52];
    int n,i=1,temp;
    cin>>n;
    getchar();
    while((a[i]=getchar())!='\n')
        i++;
    //cout<<a[i-1]<<' ';
    for(temp=1;temp<=i-1;temp++)
    {
        //cout<<a[temp]<<' ';
        if(a[temp]+n>'z')
        {
            a[temp]+=n-=26;
            cout<<a[temp]<<' ';
        }
        else
        {
            a[temp]+=n;
            //cout<<a[temp]<<' ';
        }
    }
    for(temp=1;temp<=i-1;temp++)
        cout<<a[temp];
}

by Diwanul @ 2019-09-07 13:34:47

@秋明的86

win下"\n"

linux下的"\r\n"

2个getchar()完美!


by Driver0309 @ 2019-09-07 13:45:17

@癫_妄 能否说的更详细一点,有点不是很清楚


by jacky567 @ 2019-09-07 13:46:22

@秋明的86 不能写\n,因为换行在linux中是\r\n


by syksykCCC @ 2019-09-07 13:48:08

@Jacky0705 Linux是\n, Windows是\r\n


by jacky567 @ 2019-09-07 13:48:14

@秋明的86 你要把getchar();改成getchar();getchar();


by jacky567 @ 2019-09-07 13:48:54

@syksykCCC emming上面是这么写的,虽然我也觉得很奇怪


by syksykCCC @ 2019-09-07 13:48:58

@秋明的86 它行末不一定有\n,你可以直接cin >> a;


by kongxiangzhen @ 2019-09-25 17:30:52

不用```

include<conio.h>


|