3 like 0 dislike
7.9k views
迴文判斷

迴文是指一個字串從前面讀過去跟從後面讀過去是一樣的

所以 abcdcba 是一個迴文

請寫一個程式判斷書入的字串是不是迴文

輸入說明:

會輸入一個字串,字串中間不會包含空白字元

輸出說明:

如果輸入的字串是迴文,請輸出YES,反之則輸出NO

輸入範例:

abcdcba

輸出範例:

YES
[Exercise] Coding (C) - asked in 2017-1 程式設計(一)AD by (18k points)
ID: 33757 - Available when: Unlimited - Due to: Unlimited
| 7.9k views

22 Answers

0 like 0 dislike
Hidden content!
*** * ** **** **
** * ** ******** *
** **
int *** *
{
**** ** * **** char ** = * * **
*
***** * * ** **** *** * * * ** a);
** * * * * int x = * **
** **
* * * * int i, *
******* * ** for(i = 0; i * * x / 2 ; i++)
* * * * * ** {
*** * * * * * == a[x - i - 1])
* *** ** **** * *** * * * * * * * flag = 1;
* * ** ** ** ** * *** else
*** * *** * * * * ** {
***** * ** * ** ** * * * * ***** ** * flag = 0;
* ** * ** * * * * * *** *** ** * ** *
* ** * * *** * * }
* ** * ** }
** * * * * ** ***** == 1? **** *** ** : **** *
**** *
** * ** * * 0;
}
answered by (236 points)
edited by
0 0
prog.c: In function 'main':
prog.c:7:4: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
  x=strlen(a);
    ^~~~~~
prog.c:7:4: warning: incompatible implicit declaration of built-in function 'strlen'
prog.c:7:4: note: include '<string.h>' or provide a declaration of 'strlen'
0 0
Case 0: Correct output
Case 1: Wrong output
0 0
Case 0: Correct output
Case 1: Wrong output
0 0
Case 0: Correct output
Case 1: Wrong output
0 0
prog.c: In function 'main':
prog.c:6:10: error: stray '\357' in program
  char a[]\xef\xbc\x9d\xef\xbc\x82\xef\xbc\x82;
          ^
prog.c:6:11: error: stray '\274' in program
  char a[]\xef\xbc\x9d\xef\xbc\x82\xef\xbc\x82;
           ^
prog.c:6:12: error: stray '\235' in program
  char a[]\xef\xbc\x9d\xef\xbc\x82\xef\xbc\x82;
            ^
prog.c:6:13: error: stray '\357' in program
  char a[]\xef\xbc\x9d\xef\xbc\x82\xef\xbc\x82;
             ^
prog.c:6:14: error: stray '\274' in program
  char a[]\xef\xbc\x9d\xef\xbc\x82\xef\xbc\x82;
              ^
prog.c:6:15: error: stray '\202' in program
  char a[]\xef\xbc\x9d\xef\xbc\x82\xef\xbc\x82;
               ^
prog.c:6:16: error: stray '\357' in program
  char a[]\xef\xbc\x9d\xef\xbc\x82\xef\xbc\x82;
                ^
prog.c:6:17: error: stray '\274' in program
  char a[]\xef\xbc\x9d\xef\xbc\x82\xef\xbc\x82;
                 ^
prog.c:6:18: error: stray '\202' in program
  char a[]\xef\xbc\x9d\xef\xbc\x82\xef\xbc\x82;
                  ^
prog.c:6:7: error: array size missing in 'a'
  char a[]\xef\xbc\x9d\xef\xbc\x82\xef\xbc\x82;
       ^
prog.c:11:23: error: stray '\357' in program
      for(j=x-1;i<j;j--\xef\xbc\x89
                       ^
prog.c:11:24: error: stray '\274' in program
      for(j=x-1;i<j;j--\xef\xbc\x89
                        ^
prog.c:11:25: error: stray '\211' in program
      for(j=x-1;i<j;j--\xef\xbc\x89
                         ^
prog.c:12:6: error: expected ')' before 'if'
      if(a[i]==a[j])
      ^~
prog.c:24:2: error: expected expression before '}' token
  }
  ^
0 0
prog.c: In function 'main':
prog.c:6:9: error: stray '\357' in program
  char a[\xef\xbc\x91\xef\xbc\x90\xef\xbc\x90\xef\xbc\x90];
         ^
prog.c:6:10: error: stray '\274' in program
  char a[\xef\xbc\x91\xef\xbc\x90\xef\xbc\x90\xef\xbc\x90];
          ^
prog.c:6:11: error: stray '\221' in program
  char a[\xef\xbc\x91\xef\xbc\x90\xef\xbc\x90\xef\xbc\x90];
           ^
prog.c:6:12: error: stray '\357' in program
  char a[\xef\xbc\x91\xef\xbc\x90\xef\xbc\x90\xef\xbc\x90];
            ^
prog.c:6:13: error: stray '\274' in program
  char a[\xef\xbc\x91\xef\xbc\x90\xef\xbc\x90\xef\xbc\x90];
             ^
prog.c:6:14: error: stray '\220' in program
  char a[\xef\xbc\x91\xef\xbc\x90\xef\xbc\x90\xef\xbc\x90];
              ^
prog.c:6:15: error: stray '\357' in program
  char a[\xef\xbc\x91\xef\xbc\x90\xef\xbc\x90\xef\xbc\x90];
               ^
prog.c:6:16: error: stray '\274' in program
  char a[\xef\xbc\x91\xef\xbc\x90\xef\xbc\x90\xef\xbc\x90];
                ^
prog.c:6:17: error: stray '\220' in program
  char a[\xef\xbc\x91\xef\xbc\x90\xef\xbc\x90\xef\xbc\x90];
                 ^
prog.c:6:18: error: stray '\357' in program
  char a[\xef\xbc\x91\xef\xbc\x90\xef\xbc\x90\xef\xbc\x90];
                  ^
prog.c:6:19: error: stray '\274' in program
  char a[\xef\xbc\x91\xef\xbc\x90\xef\xbc\x90\xef\xbc\x90];
                   ^
prog.c:6:20: error: stray '\220' in program
  char a[\xef\xbc\x91\xef\xbc\x90\xef\xbc\x90\xef\xbc\x90];
                    ^
prog.c:6:7: error: array size missing in 'a'
  char a[\xef\xbc\x91\xef\xbc\x90\xef\xbc\x90\xef\xbc\x90];
       ^
prog.c:11:23: error: stray '\357' in program
      for(j=x-1;i<j;j--\xef\xbc\x89
                       ^
prog.c:11:24: error: stray '\274' in program
      for(j=x-1;i<j;j--\xef\xbc\x89
                        ^
prog.c:11:25: error: stray '\211' in program
      for(j=x-1;i<j;j--\xef\xbc\x89
                         ^
prog.c:12:6: error: expected ')' before 'if'
      if(a[i]==a[j])
      ^~
prog.c:24:2: error: expected expression before '}' token
  }
  ^
0 0
Case 0: Wrong output
Case 1: Wrong output
0 0
Case 0: Correct output
Case 1: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
** *** *** ** * * *
* *** **** * ***
int main()
{
* * * * * * char a[100];
* * * * *** * * * **** * ** *
* **** {
* *** * * **** * **** int **
**** * ** * **** ** ** * ****
* ** * * * **** * * int test=y/2;
* * * * ** * * * * * **** ** **
**** * * * **   {
*** *       ***   * ****** *
** ****     **** * ** *** ** * * * * ** c++;
** * * * ** ** *** ** ** ** * else
*** * * * ** * *** * ** * * *** * * **** * ******* c=0;
* * **** * ****** * }
* ** * ** ** * * ** * * * *** *
*** * * * * **** ** * * * ** ** **** * * **** * * *****
**** * * *** * * ** *** else
** *** ** * *** *** ** * * * *** * * ***** *
* ** * }
** ** * * * return 0;
}
answered by (100 points)
edited by
0 0
Case 0: Wrong output
Case 1: Wrong output
0 0
Case 0: Wrong output
Case 1: Correct output
0 0
Case 0: Wrong output
Case 1: Correct output
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
#include * * * * * *
#include ** ** * ****
 
 int is_palindrome(char *s)
 {
**** ** ** * * * i, len;
** **** * **** *
* ***** * **** * ** ** = strlen(s);
*** *** * ** * *
** * * * ** ** * **** = 0; i < (len /2); i++) {
**** ** * * *** * * (s[i] != s[len-i-1])
* * * * ** ********* * * * **** *** * ** 0;
** * *** * ** *
***** ** * *
* *** ***** * * * (i >= len/2)
*** * ***** * * *** * ******* 1;
* * ** * **** ** *
***** * * **** * ** ** **** 0;
 }
 
 int main() {
********** *** * * * s[256];
* * * ** * * **** *
* *** ** * ** *** {
** **** **** * ** ***** * * ****
***** ** * ***** * ***
****** *** *** * ***** ** * * (is_palindrome(s))
* * ** * ** * *** * * ** ****** * ** ***** **** *** * s);
** * *** * * * * * ** * *
* ****** *** * * ** * * *** * ******* ** *** ** * ** * s);
* * * *** ***
** ****** * * * * * *
answered by (212 points)
edited by
0 0
Case 0: Wrong output
Case 1: Wrong output
0 0
prog.c: In function 'main':
prog.c:25:6: warning: 'gets' is deprecated [-Wdeprecated-declarations]
      gets(s);
      ^~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
prog.c:28:15: warning: too many arguments for format [-Wformat-extra-args]
        printf("Yes\n", s);
               ^~~~~~~
prog.c:30:15: warning: too many arguments for format [-Wformat-extra-args]
        printf("NO\n", s);
               ^~~~~~
/tmp/ccSNkWCs.o: In function `main':
prog.c:(.text+0xae): warning: the `gets' function is dangerous and should not be used.
0 like 0 dislike
Hidden content!
#include ** ** * ** ****
#include ** ** * * * *
int main()
{
* **** ** *** char * **
** * *** ******* * int i,j,z;
* * * ** * * *** * * * ** ** **** **
****** * i = *** **
** *** ** *** *** for ( j=0; * * * * * * )
* * ** {
** * *   ** ** ** * ** * ** * * *   if(str[j] == str[i - 1])
**** *** ** * ** *** ** * * * *** *** * {
* ** ** *** **** ** * ** *** ** * * z = 1;
* * * * * * * * * }
    * * * * * ** ** * * str[j] != str[i - 1] )
****** ** ***** * **** **** ** **
*** *** *     * * ** * ** **** ** * ** * * *
***   **** * * ** * * * ** ** * **** * = 0;
* *   ***** * ***** * *** ** *** ** ** * *
** * * *** ** * ** * * * *** * * **** * ** *** *
* ** ***** * ** *** * *** *
* * * * * if (z == 1)
* * ***** ** * * ** * * * ** * *** * * * * ****
* * ** * ** *****
*** *** * * ** * *** ** 0;
}
answered by (209 points)
0 0
prog.c: In function 'main':
prog.c:7:2: warning: 'gets' is deprecated [-Wdeprecated-declarations]
  gets(str);
  ^~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
/tmp/ccB79V4N.o: In function `main':
prog.c:(.text+0x3c): warning: the `gets' function is dangerous and should not be used.
0 0
prog.c: In function 'main':
prog.c:7:10: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[1000]' [-Wformat=]
  scanf("%s",&str);
          ^
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
int main(){
** * *** ** * *** s1[500];
* * * * ** *** ** i,j;
* ******* ** *** * ** **** ** * * **
* * * **** **** ** ** k=strlen(s1);

* * ** * ** ** * * ** * ** * * **
* * * * **** * ** * * * ** * * * ** * *** **
*** ** **** ** * *** * ** * **** * * * ** * ***** ** * * *** * * ** * **** * *
*** ** * * ********* *** **** * * ** ***** ** * ** *** *** * ** * *** * ** * ** *** * *
* * ** * * ** **** ** * * * * * * *** * **
    }
* ***** *** * ** * * * * ** ** **
* **** ** * * **** * * *** * * ***** ** * * ** *****
    }
** * ** ** *** ** * 0;
}
answered by (194 points)
edited by
0 0
prog.c: In function 'is_palindrome':
prog.c:6:10: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
    len = strlen(s);
          ^~~~~~
prog.c:6:10: warning: incompatible implicit declaration of built-in function 'strlen'
prog.c:6:10: note: include '<string.h>' or provide a declaration of 'strlen'
prog.c: In function 'main':
prog.c:22:6: warning: 'gets' is deprecated [-Wdeprecated-declarations]
      gets(s);
      ^~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
/tmp/ccxt7lC3.o: In function `main':
prog.c:(.text+0xae): warning: the `gets' function is dangerous and should not be used.
0 0
Case 0: Wrong output
Case 1: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#define N 20


int Cycle(char *s);


int main()
{
* * ** *** * **** * * s[N];

* *** * *** * *** * ** * *** ** * *
**** *** ** ** *** * *** * * ** * ** * * ** input word\n");
**** * ** * * ** * ** * * * *** ****** *** ***

***** * * * *** * ***** * * ** ** *** * * * == '^'){
* * * *** *** * * ** ** * ** **** * * ** *** * **** ****** *
* * ****** ** * * ***** * * * * ** * **

* ** * **** * * ** *** * * * ** ** * * *****
* **** * ***** ** * ** ******* * * *** **** * * **** * * ** * * yes!\n",s);
* * ** ** * * ** * *** *** * *** ** * ** ** *
*** *** *** * ** ******* * ** * ** **** **** ***** ** * * * no!\n",s);
** ** ** * ** * *** * *** *** * * *
    }

**** ** * *** ** ** 0;
}
int Cycle(char *s){
*** ** * * *** *** * ** * *h,*t;

* * *** * **** ** ** = s,t = s + strlen(s) - 1;t > h;h++,t--)
** ** * **** * *** * * * *** ** ** *** * * * != *t) break;

* * **** * * *** * * ***** t <= h;
}
answered by (190 points)
0 0
prog.c: In function 'main':
prog.c:14:17: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[20]' [-Wformat=]
         scanf("%s",&s);
                 ^
prog.c: In function 'Cycle':
prog.c:32:23: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
     for(h = s,t = s + strlen(s) - 1;t > h;h++,t--)
                       ^~~~~~
prog.c:32:23: warning: incompatible implicit declaration of built-in function 'strlen'
prog.c:32:23: note: include '<string.h>' or provide a declaration of 'strlen'
0 like 0 dislike
Hidden content!
#include <stdio.h>


int main()
{
    char s[100];
    int i, j, n;
* ******** * * ********* ** **** * *** * * *
** *** * *** * * * * * * * ***** ** *

* * ** * ** * * * * ***
* ** ** * ** *** ** ** ** ** **
** * ** * ** ****** * * * * * * ** * * *** * ** *** break;
* * *** ** ***** ** * * * * *** **** *
**** *** * ** * * **** * ** ** *** * **** * * * * ** * * * **
** * * * * * ****** *** ** ******* * ***
****** * *** * * * * * ** * ** * ** ** * **** **** * ** * ** * **** ** ** ** ***
*** *** * *** * ** ** * * * * * * ** ** ******* * ***** ****** 0;
}
answered by (174 points)
edited by
0 0
prog.c: In function 'main':
prog.c:8:13: warning: format '%d' expects argument of type 'int *', but argument 2 has type 'char *' [-Wformat=]
     scanf("%d",&s[n]);
             ^
prog.c:9:5: warning: 'gets' is deprecated [-Wdeprecated-declarations]
     gets(s);
     ^~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
prog.c:11:7: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
     n=strlen(s);
       ^~~~~~
prog.c:11:7: warning: incompatible implicit declaration of built-in function 'strlen'
prog.c:11:7: note: include '<string.h>' or provide a declaration of 'strlen'
/tmp/ccDYUh1t.o: In function `main':
prog.c:(.text+0x3f): warning: the `gets' function is dangerous and should not be used.
0 0
prog.c: In function 'main':
prog.c:8:13: warning: format '%d' expects argument of type 'int *', but argument 2 has type 'char *' [-Wformat=]
     scanf("%d",&s[n]);
             ^
prog.c:9:5: warning: 'gets' is deprecated [-Wdeprecated-declarations]
     gets(s);
     ^~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
prog.c:11:7: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
     n=strlen(s);
       ^~~~~~
prog.c:11:7: warning: incompatible implicit declaration of built-in function 'strlen'
prog.c:11:7: note: include '<string.h>' or provide a declaration of 'strlen'
/tmp/cc47s844.o: In function `main':
prog.c:(.text+0x3f): warning: the `gets' function is dangerous and should not be used.
0 0
prog.c: In function 'main':
prog.c:11:7: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
     n=strlen(s);
       ^~~~~~
prog.c:11:7: warning: incompatible implicit declaration of built-in function 'strlen'
prog.c:11:7: note: include '<string.h>' or provide a declaration of 'strlen'
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include<stdlib.h>

int main()
{
    char s[100];
    int i, j, n;
**** ***** * * ****** ** * ** *** *** ** ***
******** *** * * *

* ** **** *** ***** *** **
** *** **** * * * ******* ** ****
** **** * * * ** ** ** * *** * * * * * * ** * **** * * break;
* *** **** **** * *** **** * *** * * ** *** ** * *** ** ***
* *** * **** ** ** * * * * * * * * ***** ***** * ** *** ** * *** ** * * ** ***
** * ** ** * * ** **** * * *
***** *** * *** *** * * *** * * ** * * ***** * ** * ***** ** * ***** ** *** ** ** * * * *
}
answered by (174 points)
0 0
prog.c: In function 'main':
prog.c:8:13: warning: format '%d' expects argument of type 'int *', but argument 2 has type 'char *' [-Wformat=]
     scanf("%d",&s[n]);
             ^
prog.c:9:5: warning: 'gets' is deprecated [-Wdeprecated-declarations]
     gets(s);
     ^~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
prog.c:11:7: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
     n=strlen(s);
       ^~~~~~
prog.c:11:7: warning: incompatible implicit declaration of built-in function 'strlen'
prog.c:11:7: note: include '<string.h>' or provide a declaration of 'strlen'
/tmp/ccjI8t0q.o: In function `main':
prog.c:(.text+0x3f): warning: the `gets' function is dangerous and should not be used.
0 like 0 dislike
Hidden content!
#include ** ** * *
#include ** ** * * ** *
** ** ** *
int is_palindrome(char *s) {
* *** *** ** ** * i, len;
* *** * * * *
******* * * ***** = strlen(s);
*** * * * ** * * *
* * * **** = 0; i < (len /2); i++) {
** * * ** * ***** * ** * (s[i] != s[len-i-1])
*** * ** ** ** * ** *** * * **** *** ***** * * 0;
* * * **
* ***** * ** *** * * ***
** * *** ** ** * * * (i >= len/2)
* * * * ****** * *** * * * 1;
** * *** * * * *******
* ** * * * * * *** * **** 0;
}
  
int main() {
* ** ** ** ** s[256];
** ** * * ** * * * *
**** ** * * **** {
** * * * ** **** * ** * * * ** **
** **** **** *** * ** * ****
***** * *** * * * *** ** (is_palindrome(s))
** *** ** **** ** * ****** *** ***** * * ** ** * * ** ** * *
****** ** **** * * *** ** * *
* *** ** * * *** ** ** * ** * ** * * * ** *
* *** * * *
}
answered by (160 points)
0 0
prog.c: In function 'main':
prog.c:24:6: warning: 'gets' is deprecated [-Wdeprecated-declarations]
      gets(s);
      ^~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
/tmp/cc7oj25o.o: In function `main':
prog.c:(.text+0xae): warning: the `gets' function is dangerous and should not be used.
0 like 0 dislike
Hidden content!
** * * * * * **** *
* * * ***** *
int main()
{
** **   char ******* *
* * *** * **** int a,b,c;
* * * ****
** * ** ***** * * ** * * EOF)
* ** ** * {
* ** ** * * * b = 1;
* ** * ***** ** ** ** * a = ** ** *
* * * ** * * ** ** ***
*** * **** ** * * *** ** ** ** *** a/2;c++)
** ** * *** * * ** ** {
* * * ***** *** **     ** ***** * *
* * **     ** **     {
*     ** * * * ** *** * b=0;
* * * *** * ** ** *** **** ** ** ** *** * ** break;
** ** * * * * * ** ** * *** }
**** * * * * ** ** **** }
* * * * ** * if(b)
* * * * * * * * * *** ** * * * ******
** * * * *** else
* ** ** * ** * **** * **** * ***** **** * ** ** ** * *
****** * *** * *** * * ** *
* * * * ** *** * * * *** * * **** break;
* * * * * }
* * * **** * ** * *** ** **
** *** *** return 0;
** ** ******* *
*** **
answered by (160 points)
0 0
prog.c: In function 'main':
prog.c:28:2: warning: implicit declaration of function 'system' [-Wimplicit-function-declaration]
  system("pause");
  ^~~~~~
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.126.217
©2016-2025

Related questions

2 like 0 dislike
24 answers
[Exercise] Coding (C) - asked Nov 16, 2017 in 2017-1 程式設計(一)AD by Shun-Po (18k points)
ID: 33762 - Available when: Unlimited - Due to: Unlimited
| 6.9k views
3 like 0 dislike
20 answers
[Exercise] Coding (C) - asked Nov 16, 2017 in 2017-1 程式設計(一)AD by Shun-Po (18k points)
ID: 33758 - Available when: Unlimited - Due to: Unlimited
| 6.3k views
3 like 0 dislike
9 answers
[Exercise] True/False - asked Nov 16, 2017 in 2017-1 程式設計(一)AD by 楊修俊 (30k points)
ID: 33763 - Available when: 2017-11-16 14:00 - Due to: 2017-11-16 14:30
| 1.4k views
3 like 0 dislike
5 answers
[Exercise] Coding (C) - asked Nov 30, 2017 in 2017-1 程式設計(一)AD by Shun-Po (18k points)
ID: 34978 - Available when: Unlimited - Due to: Unlimited
| 2.7k views
3 like 0 dislike
6 answers
[Exercise] Coding (C) - asked Nov 30, 2017 in 2017-1 程式設計(一)AD by Shun-Po (18k points)
ID: 34979 - Available when: Unlimited - Due to: Unlimited
| 2.6k views
12,783 questions
183,442 answers
172,219 comments
4,824 users