0 like 0 dislike
991 views
 

請設計一個程式,使用者會輸入一個字串,請判斷該字串是否為回文(palindrome)。

 

輸入範例1:

12321

輸出範例1:

12321 is a palindrome

輸入範例2:

apple

輸出範例2:

apple is not a palindrome

[Normal] Coding (C) - asked in 2016-1 程式設計(一)AC
ID: 20482 - Available when: Unlimited - Due to: Unlimited

reshown by | 991 views
0 0
Called for Help

31 Answers

0 like 0 dislike
Best answer
Hidden content!
* * * *** * **
* * * * ** ** * *
* ** * * ** * ** *

#include <ctype.h>

int main(void)

{
* **** **** ** ** * * i,len;
* * * * * * * * * ** s[100];
* ** ** *** * * ** **
* * ** * * ** ** **** ****
** ** * * * ** *** ** = 0;i < len / 2;i++)
** ** * *** * * ** *
** * **** ** * * *** * ** * * **** ** ** != s[len-i-1])
* * * ** *** * *** ** * ** * * * * * **** ** **
* *** * ** *** **** * * * * ******* ** *** * *** ** * is not a palindrome",s);
* * * * ** * * ** ******* ** * **** * * * * *** *** ***
** * * ** * * * * *** * ** ** **** ** * * ** * ****
* * ** *** * * *
* ** * ** * * * *** * (i >= len / 2)  
** ** * ***** * * * *** * ****** * ** is a palindrome",s);

}
answered by (-124 points)
0 like 0 dislike
Hidden content!
**
answered by (-276 points)
0 like 0 dislike
Hidden content!
*** ******* * * *

* * ** ****** * ***

** * ***** * ***



int main (void)

{ ***** *** *
* *** ** * ** ***** a,b,c,d,i,k,j;

* * * * * ** * * **** * s[99],z[a-1];



* * * * ***** ** ** *** * ** *

* * **** * *** * ** ** ** * *

* * * * * * ********* * **
**** ****** * * * (s[a-1]==s[0])

**** ** *** * ****** ("%s is a palindrome",s);

* * * * * *

****** **** * *********** ("%s is not a * * * *

*** ** * ***** ***** **** *
*** * * * ** ** ** * *


* * * * * * *** ** *** *** ** 0;

}
answered by (-122 points)
0 like 0 dislike
Hidden content!
**** ***** * ***

*** * * ** **

** ** * * ****

*** * ****



int main ()

{ * * * * * * * **
* * * * **** ** * a;

*** ** * * * * *** * ** s[99];



**** ***** * ** * * ** * * ** ** **** * * *

** ** ** ** ** ** * *

** * ** * * * ** **** * *
** * *** * ***** ** * * * (s[a-1]==s[0])

***** * * * ** ** ** * *** ("%s is a palindrome",s);

********* ** ****** * *

***** * * * *** * * ("%s is not a palindrome",s);

* *** **** * ** * ***
** * *** * * *** **** ***


** ** * ** ** ** 0;

}
answered by (-102 points)
0 like 0 dislike
Hidden content!
#include ** *** **

#include * * * ***


*** ** ** * *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 a *** * * * s);
*** **** * * *** * * ********
**** ** * * **** * * *** * * * ** ** * *** * is not a ** *** * * s);
* * ** *** **

 }
answered by (-143 points)
0 like 0 dislike
Hidden content!
#include  <stdio.h>

#include  <assert.h>

#include  <stdlib.h>

#include  <string.h>



int  main(void)

{
******** * ** ** ***** ** ** i,j=0,flg=0;
**** ** * ** * * *** *** * **** a[10],b[10];
** ** *** * ** **** * ****
* *** ** * ** * **** ** * * * * **
* * * * ** * ** ** ** *** ** * *** * **
******* * * * ** * * *** * -1;i--){
* ** ****** **** *** * * ***** * * ** ** * **
** * *** * * * * ** * * * ** * *** * * ** * * * *** *** * *** * * **
*** * * ** * ** *** * * * * * ** * ******* *** * *
* *** *** ** * * * * * *** * *******
** ** * * * *** * ** *
* * *** * * * ***** * * * ******
* * * ***** * * * * * * * *** * ** * * ***
** * * * * ** *** ** * * ** * *** **** * ** * * ** * * *** *** * * * * *
* * ** * ** * * * * ** **** * *** * ** ****** * * * ** *** * ** * * ** * * * * *
*** ** ** * ***** **** * ** ** ** **** * * * *** * * * * ** ** * * *** ** * * * *** ** *
* * * *** ***** *** * *** * * *** * * ** * ** ** * * *** *** ** *
* **** ** * * *** * *** * ***** *** * * *** *** *****
* * *** **** * **

    
* * * * * * * * * *
** * * ** * * * * ** *** ***** ** ** *** * is a palindrome",a);

    }
*** *** * ** *** *** ***
* *** ** * ** * ** *** *** * ** * * ** ** *** * *** is not a palindrome",a);

    }
** * * * ** *  0;

}
answered by (-158 points)
0 like 0 dislike
Hidden content!
* *** * ** *** * * **
* ** ** * * **** **
* * **** * ** **
* * *** * * ******



int main (void)

{ * *
* ** ***** * * a,b,c,d,i,k,j;
* * *** *** **** * * * s[99],z[a-1];


*** * * *** *** ** ** ** ** ** ***
*** * * * *** * ** ** **
* ** ** * * *** * *
**** ** * ** * * **** (s[a-1]==s[0])
* * ****** * ** ** * ** ("%s is a *** *
**** * * * * ** **
** * * ** ****** *** ("%s is not a * **** **
**** ** ** **** ** * *
** ** * * * * *



    return 0;

}
answered by (-136 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include * **********



int main(void)

{
** * * ** **** ** * s[100];
*** * * * * ** ** *** i, j, n;
***** ***** * *** *** * *
* * * ** * *** ** * **
* **** * **** ** * ** ****
**** ** * *** * * * * * * * ** ***
** * *** * * **** * *** ** **** break;
** * * *** * *** * ** * * ** * * * ** * *
*** * * ** ** * * **** **** * * *** * **** * is a palindrome\n", s);
** *** * ** * **** * * * * *
* * ***** ** ** * ** * ** ******* *** * * * ** is not a palindrome\n", s);
* * **** * * * *** * 0;

}
answered by (-100 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include ** * ** * * **

 

int is_palindrome(char *s) {
** * * *** ** * i, b;
* *** ** *** * * **
** * ** * ** ** ***** = strlen(s);
* ***** ** *
* * ** ** *** * ** * = 0; i < (b /2); i++) {
* * *** **** *** * **** *** (s[i] != s[b-i-1])
** ** ******** * * ** ** * * ** * * 0;
* ** * * * ****
* *** * * * * **** (i >= b/2)
***** *** * ** * **** * * * 1;
* * *** ** * ** * *
* * ** ** *** ***** * ** ** 0;

}

int main()

{
* * ** * * * * * s[256];
** ** * *
** * * *** **** * *

* * * * ** ** ** *
** * ** * ****** ** * ***** *
* * ****** ** * * *
* * ** * ** * *** * ** (is_palindrome(s))
*** **** * * * ** ** ** * ** ****** ** ***** ** is a * ** *** s);
* * * * * ********** ** *
** ***** ** * ** * ** *** *** * * * *** *** * * is not a ***** * ** * * s);
* *** * * ** * * ** * * * 0;
** **** ** * * ***

}
answered by (-100 points)
0 like 0 dislike
Hidden content!
#include * **** ** ** ***

#include * * * * **

 

int is_palindrome(char *s) {
** * * ** * * i, b;
******* * * *
* ***** ** * * = strlen(s);
* * **
** **** **** ***** * = 0; i < (b /2); i++) {
*** ** ** * ** **** *** ** * (s[i] != s[b-i-1])
* ** *** ** * * ** ** * ** ** ** 0;
* * *** * *
****** ****** * * (i >= b/2)
* * * *** **** * ** * **** * * 1;
* * * * ** *** *****
** * ***** * **** *** ** * 0;

}

int main()

{
** * ** ** * * * ** s[256];
** * *** * * **
* **** *** ***** *

* **** **** * * *
** * * * ** * * * ** *
**** **** *** * * *** ** ****
** * * * *** * **** (is_palindrome(s))
* ** * ** *** ** **** * * * * * *** * * * * is a palindrome\n", s);
** * **** * **** **** ** * * ** **
** ** * ***** **** *** ** * **** *** * * ** ** *** is not a * *** * * * s);
* *** *** **

}
answered by (-100 points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.71.254.166
©2016-2024

Related questions

0 like 0 dislike
7 answers
[Normal] Coding (C) - asked Jan 5, 2017 in 2016-1 程式設計(一)AC by 林佳慧 (-85 points)
ID: 20976 - Available when: Unlimited - Due to: Unlimited
| 282 views
0 like 0 dislike
24 answers
asked Dec 7, 2016 in 2016-1 程式設計(一)AC by Shun-Po (18k points) | 583 views
0 like 0 dislike
3 answers
[Normal] Coding (C) - asked Jan 5, 2017 in 2016-1 程式設計(一)AC
ID: 20997 - Available when: Unlimited - Due to: Unlimited
| 203 views
0 like 0 dislike
3 answers
[Normal] Coding (C) - asked Jan 3, 2017 in 2016-1 程式設計(一)AC by 410425014 (-162 points)
ID: 20514 - Available when: Unlimited - Due to: Unlimited
| 226 views
0 like 0 dislike
5 answers
[Normal] Coding (C) - asked Dec 27, 2016 in 2016-1 程式設計(一)AC by 410342026 (-105 points)
ID: 20135 - Available when: Unlimited - Due to: Unlimited
| 292 views
12,783 questions
183,443 answers
172,219 comments
4,824 users