有好心人帮忙挑一下错吗??

样例过了,评测死活不能AC
c++
#include<iostream>
#include<cstdlib>
using namespace std;
int n;
bool pd(string sta,string stb,string stc)
{
bool b;
int a1,a2,a3;
b=true;
for (int i=0;i<=n-1;i++)
{
a1=sta[i]+1;
a2=stb[i]-1;
a3=stc[n-i-1];
if (a2<97) a2=a2+26;
if (a1>122) a1=a1-26;
if (a1!=a2||a1!=a3||a2!=a3)
b=false;
}
return b;
}
void sc(string str)
{
for (int i=n-1;i>=0;--i) cout<<str[i];
exit;
}
int main()
{
string st1,st2,st3;
cin>>n;
cin>>st1>>st2>>st3;
if(pd(st1,st2,st3)){ sc(st3); exit;}
if(pd(st2,st1,st3)){ sc(st3); exit;}
if(pd(st1,st3,st2)){ sc(st2); exit;}
if(pd(st3,st1,st2)){ sc(st2); exit;}
if(pd(st3,st2,st1)){ sc(st1); exit;}
if(pd(st2,st3,st1)){ sc(st1); exit;}
system("pause");
return 0;
}

4 条评论

  • @ 2017-07-03 22:13:26

    不过真心没遇到汉字什么情况喵。修改了大佬所说的0<=K<=6的问题,并把exit改为了exit(0) (原谅我一时眼花╮(╯_╰)╭ ),再次表示对大佬的敬意,太谢谢了!

    #include<iostream>
    #include<cstdlib>
    using namespace std;
        int n;
    bool pd(string sta,string stb,string stc)
    {
        bool b;
        int a1,a2,a3;
        for (int k=0;k<=6;k++)
        {
        b=true;
        for (int  i=0;i<=n-1;i++) 
        {
            a1=sta[i]+k;
            a2=stb[i]-k;
            a3=stc[n-i-1];
            if (a2<97) a2=a2+26;
            if (a1>122) a1=a1-26;
            if (a1!=a2||a1!=a3||a2!=a3)
            b=false;
        }
            if (b) { return b;break;}
        }
        return false;
    }
    void sc(string str)
    {
        for (int  i=n-1;i>=0;i--) cout<<str[i];
        exit(0);
    }
    int main()
    {
        string st1,st2,st3;
        cin>>n;
        cin>>st1>>st2>>st3;
        if(pd(st1,st2,st3)){ sc(st3); exit(0);}
        if(pd(st2,st1,st3)){ sc(st3); exit(0);}
        if(pd(st1,st3,st2)){ sc(st2); exit(0);}
        if(pd(st3,st1,st2)){ sc(st2); exit(0);}
        if(pd(st3,st2,st1)){ sc(st1); exit(0);}
        if(pd(st2,st3,st1)){ sc(st1); exit(0);}
        system("pause");
        return 0;
    }
    
  • @ 2017-07-03 22:05:30

    @沉江底@mrkrnblsa 问题已解决,谢谢谢谢!!(表示pascal转c++好累)

  • @ 2017-07-01 11:13:16

    好像还有一个地方吧,那个你是不是默认k值为1了(逃

  • @ 2017-07-01 08:11:21

    if (a1>122) a1=a1-26;
    这句看上去没错,但问题是电脑有时候会把一些ascll大于127的字符进行一些神奇的处理,这样你就会因为这句话错了。具体点,汉字是由两个ascll组成的,再具体点我也不知道了。。

    • @ 2017-07-01 11:02:19

      这题好像数据里面没有汉字欸

    • @ 2017-07-01 11:06:24

      @沉江底: char类型好像有个奇怪的设定,如果某个char的值超过127并且连续输出两个这样的char就会输出一些奇怪的东西,在中国就是汉字了,非英语国家好像输出当地的语言文字,具体参见各种百科。。

    • @ 2017-07-01 11:08:40

      @mrkrnblsa: 哦这样啊(233333

    • @ 2017-07-01 11:18:50

      不过我觉得你讲的这个问题他应该不会遇到呢。。。它已经把大于122的字符-26了呀,怎么还会有大于127的字符

    • @ 2017-07-01 17:27:31

      @沉江底: 问题是减去26之前有可能大于127。这个可以验证一下,比如说一个char赋值为‘A'另一个赋值为’C‘,然后把它们加上100再减去100,连着输出这两个值应该会是一个汉字。当然这种情况用我几个小时前说的确实解释不通,还请大佬支援。。。(另,强烈建议vj搞一个提示系统,否则被@了还不知道。。。)

    • @ 2017-07-01 22:29:32

      @mrkrnblsa: 我想了一下,下面纯属个人猜测,(因为我c也学的不好2333),求正规解答:char处理中文的机制是如果某个字符的值大于127(即第一位为1的时候,这个时候输出这个char就是一个负值)就认定这个字符后面还要读入一个字符(好像并不需要后面这个字符也大于127。。)然后用这两个char值对应出一个汉字,而如果一开始就加出127不过是把这个char加成了130多,但是用a[]取这个char的时候依旧取出来的是单个的char,所以应该不会取出个汉字来,所以再去-这个东西自然就减回到122以内了吧,似乎只有输出的时候有你说的那种机制吧。。。(而且我回头翻了一下我的代码好像我也是大于122后直接减26的然后过了23333)

    • @ 2017-07-04 08:30:52

      @沉江底: 。。。好吧看来是我的脸太黑了。。。

  • 1

信息

ID
1449
难度
6
分类
字符串 | 模拟 点击显示
标签
递交数
6904
已通过
1851
通过率
27%
被复制
9
上传者