字符串回文程序 [英] Program for string palindrome

查看:85
本文介绍了字符串回文程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码执行为infinte循环或有时没有结果..

plz help



我试过的:



the code executes to be infinte loop or no result at times..
plz help

What I have tried:

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{
   clrscr();
   int i,len,j=0,flag,k,f;
   char str[100],king[100];

   cout<<"enter a string";
   gets(str);
   cout<<" the string you have entered is "<<str<<endl;
   len=strlen(str);
   for(i=0;i<len;++i)
   {
     if(str[i]!=' ')
     {
       king[j]=str[i];
       j++;
     }

     if(str[i]==' ')
     { 
       king[j]='\0';

        for(f=0,k=1;f
        {

         if(king[f]==king[j-k])
         {
            flag=1;
            break;
         }
         else
         {
            flag=0;
            break;
         }
       }
     }

    j=0;
    if(flag==1)
       cout<<"YOU HAVE ENTERED A STRING PALINDROME which is"<<king;
 }
getch();
}

推荐答案

7月8日,您发布了相同的代码作为一个问题:查找字符串回文的代码 [ ^ ]

你收到了3个答案,所有这些都告诉你要做同样的事情:使用调试器。

你不喜欢这个想法,我可以说:部分是因为你de由于你的帐户被关闭,因此在马拉雅拉姆被辱骂,部分是因为十天后代码仍然相同。

所以...建议保持不变:使用调试器。
On the 8th July, you posted this same code as a question: Code for finding string palindrome[^]
ANd you received 3 answers, all of which told you to do the same thing: use the debugger.
You didn't fancy the idea, I can tell: partly because you decided to be abusive in Malayalam as a result of which your account was closed, and partly because ten days later the code is still the same.
So... the advice remains the same: use the debugger.


您应该学习尽快使用调试器。而不是猜测你的代码在做什么,现在是时候看到你的代码执行并确保它完成你期望的。



调试器允许你跟踪执行逐行检查变量,你会看到它有一个停止做你期望的点。

调试器 - 维基百科,免费的百科全书 [ ^ ]

掌握Visual Studio 2010中的调试 - A初学者指南 [ ^ ]



建议:拿一张纸,然后用你做的东西来检查字符串是否是回文。使用调试器查看程序不符合您的期望。
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

Advice: take a sheet of paper and mote what you do to check if the string is a palindrome. Use the debugger to see where the program don't follow your expectations.


这篇关于字符串回文程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆