| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1338 人关注过本帖
标题:为啥无法连续判断回文
只看楼主 加入收藏
yayajpg
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2021-9-8
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
为啥无法连续判断回文
#include <iostream>
using namespace std;
int main()
{
    int a,b,c,d,a1,b1,c1,d1;
    char ai[100];
    char bi[100];
    int ci[100];
    char di[100];
    for(a=0;ai[a]!='\0';a++)
    {
    cin>>ai[a];   
    a1++;   
    }
    for(b=0;bi[b]!='\0';b++)
    {
            cin>>bi[b];
        b1++;   
    }
    for(c=0;ci[c]!='\0';c++)
    {
        cin>>ci[c];
        c1++;   
    }
    for(d=0;di[d]!='\0';d++)
    {
        cin>>di[d];
        d1++;   
    }
    if(ai[a++]!=ai[a1--])
    {
        cout<<"case1: no"<<endl;
    }
    else
    {
        cout<<"case1: yes"<<endl;
    }
    if(bi[b++]!=bi[b1--])
    {
        cout<<"case1: no"<<endl;
    }
    else
    {
        cout<<"case1: yes"<<endl;
    }
    if(ci[c++]!=ci[c1--])
    {
        cout<<"case3: no"<<endl;
    }
    else
    {
        cout<<"case3: yes"<<endl;
    }
    if(di[d++]!=di[d1--])
    {
        cout<<"case4: no"<<endl;
    }
    else
    {
        cout<<"csae4: yes"<<endl;
    }
    return 0;
}
搜索更多相关主题的帖子: cout 判断 for cin char 
2021-09-09 09:36
diycai
Rank: 8Rank: 8
等 级:贵宾
威 望:19
帖 子:147
专家分:895
注 册:2021-5-18
收藏
得分:7 
#include <stdio.h>
#include <string.h>

void fun()
{
    int len, i;
    char s[100];

    scanf("%s", s);
    len = strlen(s);

    for (i=0; i<len/2; i++)
    {
        if (s[i] ^ s[len-1-i])
        {
            printf("No\n");
            return;
        }
    }

    printf("YES\n");
}

int main()
{
    while (1)
    {
        fun();
    }
   
    return 0;
}
2021-09-09 11:25
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9029
专家分:54050
注 册:2011-1-18
收藏
得分:7 
从代码上看得出你丝毫不会C/C++,那为什么不肯用汉语描述清楚你的需求呢?
,我猜你需要的可能是:

程序代码:
#include <iostream>
#include <string>
using namespace std;

bool is_palindrome( const std::string& word )
{
    for( size_t i=0; i!=word.size()/2; ++i )
        if( word[i] != word[word.size()-1-i] )
            return false;
    return true;
}

int main( void )
{
    size_t index = 0;
    for( std::string word; cin>>word; )
    {
        cout << "case" << ++index << ": " << (is_palindrome(word)?"yes":"no") << '\n';
    }
}
2021-09-09 13:52
自由而无用
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:61
专家分:1456
注 册:2021-8-9
收藏
得分:7 
//online parser: https://www.bccn.net/run/
程序代码:
#define iostream <stdio.h>
#include iostream

#include <stdlib.h>

//#pragma GCC diagnostic ignored "-Wpointer-to-int-cast"
//#pragma GCC diagnostic ignored "-Wint-conversion"
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast"

#define X64_ABI
#define PRINT_ON 1

void fill_vector(void *vx, ...)
{
    //X64 using a new system-V ABI totally different from old x86-platform
    //rdi,rsi,rdx,rcx,r8,r9
    register int pid asm("%rsi");
    register int vid asm("%rdx");

    int i;
    static int p, v;

#define VA_PID 0
#define VB_PID VA_PID + 1
#define VC_PID VA_PID + 2
#define VD_PID VA_PID + 3
#define VA_VID main
#define VB_VID VA_VID + 0x1000
#define VA_LEN 511
#define SYM 0x0C3
#define CAST2A(a, v) ((unsigned char *)(a))[v]
typedef unsigned char(*vt)[VA_LEN + 1];
#define CAST2AE(x, p, v) ((vt)(x))[p][v]

#ifndef X64_ABI
    //old x86 ABI abandoned!!
    //bypass local variables
    //local [+0x28]i 
    //__asm__("popq %rax");//skip i
    //__asm__("popq %rax");//skip i x64 specified
    //[+0x20]v->[0x18]p->[0x10]vx->[0x8]pid->[0x0]vid
    //__asm__("popq %rax");//skip vid random reg
    //__asm__("popq %rax");//skip pid random reg
    //__asm__("popq %rax");//skip vx
    //arg1
    //__asm__("popq %rax");//get arg_p
    //arg2
    //__asm__("popq %rdx");//get arg_v
#endif

#define SAV(_s, _id) (_s) = (_id)
    SAV(p, pid);
    SAV(v, vid);

    for(i = 0; CAST2A(v, i) != SYM; i++) {
#define name(_s) #_s
        //bug fixed cause of X64 ABI
#define BUG_ON_PRINTF_NOW_ITS_OKAY
#if(0 == PRINT_ON)
        printf("%02d: %s[%02d] = 0x%x\n", i, name(main), i, CAST2A(v, i));
#endif
        CAST2AE(vx, p, i) = CAST2A(v, i);
        if(0xff == CAST2AE(vx, p, VA_LEN)++)
        CAST2AE(vx, p, (VA_LEN - 1))++;
    }
}

void compile_x86_abi(void)
{
#ifndef X64_ABI
    //online parser have no root to play, 2333
    system("sudo apt-get install libc6-dev-i386");
    system("gcc -m32 *.c -o v.out");
    system("ls");
#endif
}

int main(int argc, char *argv[])
{
    unsigned char vector[4][VA_LEN + 1];
    int i, j;
    
#define PID(_p) V##_p##_PID
#define VID(_v) V##_v##_VID
    fill_vector(vector,  PID(A), VID(A));
#define vsa vector[VA_PID]
#define vlen(_v) _v[VA_LEN] + _v[VA_LEN - 1] * 0x100
#if(0 == PRINT_ON)
    printf("len = %d, ret = 0x%x\n", vlen(vsa), CAST2A(VID(A), vlen(vsa)));
#endif

#define cout puts(
#define endl )
#if(0 == PRINT_ON)
    for(i = 0, j = vlen(vsa); i < j; i++, j--) {

        if(vsa[i] != vsa[j]) cout"case1: no"endl;
        else cout"case1: yes"endl;
    }
#else
    cout"PRINT_ON(0)/OFF(1)"endl;
#endif
    compile_x86_abi();

    return 0;
}


[此贴子已经被作者于2021-9-10 16:15编辑过]

2021-09-09 15:56
快速回复:为啥无法连续判断回文
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027602 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved