0 like 0 dislike
8.9k views

This program will receive a sentence and reverse it as the result. 字串反轉

Example input 1:

School need Student

Example output 1:

Student need School

Example input 2:

Student

Example output 2:

Student

Example input 3:

are you as bored as I am

Example output 3:

am I as bored as you are

 

[Exercise] Coding (C) - asked in Chapter 13: Strings by (12.1k points)
ID: 41436 - Available when: Unlimited - Due to: Unlimited

edited by | 8.9k views

29 Answers

0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<string.h>

int main()
{
    int i,j,k,end; //end 要解決最後多出\0的問題
    char a[100];
    scanf("%[^\n]%*c",a);
    j=strlen(a);
    end=j-1;
    for(i=j-1;i>=0;i--)
        {
* ** ** **** * ** ******** * ** *** **** * ** * * * ****** * * *** *** ** * ')
* * *** * * *** ** ** * *** *** ** * *** ** ** *** ** * * * ** * ** ***** ***
** ***** ****** * * *** ** * *** *** * *** * * * ** ******* *** * ***** *** * * ****** * *** * * *** ** *** * **
** ** * ** * ***** * * *** *** ** *** **** * * * ** * * * * * **** **** *** **** *** * *** * * ***** * * *** ** * **** * *** *****
** * ******* * *** ** ** ** * * * * * * ** **** * * ** * ****** *** ** **** * ** * ** *** *** * * * * **** **** ** *** * **** **** ** *** * ** * ** ** * * *
* * ** ****** * * * * * ** ** * * * ** * * *** * *** * ** * * **** *** * * ********* *** ** ** * ** * ** ** ** * * * *
** ** ** *** ** * * ** * * ** **** * * *** *** *** * * ** * ** *** ** *** ** **** *** ** **** *** ** * ");
* * * ** ** * * * ** ** ***** **** **** **** *** * * *** *** ** *** ******* ** *** * * * * ****** * ** * * * **
**** * * ******* ****** * * *** * *** ** * * **** ** ** ** ** * *** *** ******* * * * * *
* **** ***** * *** * ***** ** * ** **************** * * *** * ** * if(i==0)
*** * ** * **** * * **** * * *** * ** ** * * ** * **** * *** * *** * *
* * * *** ** ****** ** * * ** * ** * *** * * * * * *** *** * * *** ** *** * ******** **** *** **** *** **** *** * **
* * * * *** * ****** ** * *** * ** * **** * ** *** * * ** *** * * *** * * ** ** * *** * **** ** ** * ** * * * ** * ***
* * ** *** ** * ** * * ***** ** * *** * ** * **** * ** * * *** ******** * ** * * ** * ** * *** * * * *** * ** * * *** * * * * ** *** ** *** ** **** * **** * * *
* ** * **** * * ** * * ******** * * * * ****** ** * * ** * * ** ***** * *** * * * **** * * * ** ** ** * **** * * * * * ** ** ** *

* * *** * *** ****** ** ** ***** **** *** ** * * *** * * ** *** ** * **** * *** *
        }

return 0;
}
answered by (-258 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>

void reverse(char *begin, char *end);
void reverseWords(char *s)
{
*** *** ** ** * * ** ** * * * *word_begin = s;
* **** ** * ** ** *temp = s;
** * ** * ** ** ** * * * * * *temp )
    {
**** * * ** * * * * * ** * ***** * * * *
******* * ** ** * * *** *** * ******* * (*temp == '\0')
*** *** *** ** **** * * * *** ** ** * ***
**** * ** **** ** *** * * *** **** * * * * ** * * * * ** * ***** * * * *** *** temp-1);
** ** **** * * * * * ** ** * * * *** * * *****
*** **** ** * ***** ** * * * * * *** if(*temp == ' ')
* ** * * * * * ** ** * ** **
**** ***** *** * * * ** * * *** ** * * * * *** ** * ** * ** ** temp-1);
* * * ****** *** * ** **** * * * ***** ** ** ******* * ** * * = temp+1;
*** * * ** *** * *** * **** * ***** *
** * * * ******** * ** *
* ** **** * * * * ** *** * * temp-1);
}
void reverse(char *begin, char *end)
{
** * ** ** * * * * * * ** temp;
* * ** **** ** * **** * (begin < end)
*** ** ****** * ** **
* *** * * * ** * ***** * ** ****** ** * * = *begin;
**** * ***** * ***** * ** * ** ***** * **** ****** * ** = *end;
** ** * * * * * * ** * ** ** **** *** * * ** = temp;
    }
}

int main()
{
*** *** ** ** * * *** s[1000];
** ** ** ** ******* * * ** **** ** s)  ;
* ** ** * *** * * **** *** *temp = s;
** ****** ** **** ** *
* ** ***** * ** * * * ** * * * * *** s);
* * * *** *** * ** 0;
}
answered by (323 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>

int main()
{
* * ** ** *** * * **** ** str[100], rev_word[100];
* **** *** * * **** length, i;
*** ** ******* * * ** *** sword,eword;
*** **** * * * * **** index;
    
    
** *** *** *** * ** *** ** **** * ** * * * ****
    
* ** ** ** *** ** *** * * = (unsigned)strlen(str);
* * ** * * ** * * *** = 0;
** * *** *** *
  
** * * ***** * ** * * = length - 1;
* **** ** ****** * * * * = length - 1;
    
* ** * * * * * * * * * * *** > 0)
* ** ** **** ****** * *
* *** * ** **** ******* * * ******
*** * *** *** * ** ***** *** ** *** * **** * == ' ')
* **** * * * * * *** * * ** *** * *** ** * **
* ******* * ** *** **** *** ******** ** * * * **** *** ** * ** * ****** ** **
** ** * ** ** * * * * * ** ** * ** *** *** ** ** ** *** * * = sword + 1;
* * * * * *** ***** * * * * **** **** * * ** * * * ** * * **** <= eword)
* * ** * *** *** * * * * * *** *** ** * * * * **** * *** * * **
* ***** ** * ** * * * ******** ** ** ** * ** ** * * ** * **** ******* ** * *** **** * = str[i];
**** *** * ** * ** * ** ** ** *** ******** * * ** * * * * *** ** * * ** ***** ***
* ** ** ** ********* ** ** * * * * *** * * * ** * *** ** **** ** * * *
* * * ** ****** * ** * * * ** * * * * * * * * ** * * * ** * *** ** ** * * * ** ****** *
** * * ** ** * **** *** ** * ** * * * ** ***
*** * ** * * *** * ** * * ** * * * ** *** ** *** * * * * *** * * * = ' ';
* ** * * ** * * ***** * * * * ** * ** *** * *** * ** **** * * ** * *
* * * ** * *** ** *** ** ** ***** ** * * * ** ** * * * * * ** = sword - 1;
******* * * * ** * ** * * * ** *** *
*** **** * * * * ** * *** * ** *** *
* ** * ** ** ***** ** ** *** ** * * ******* * *
*** * **** **** * * ** *
    
    
* * * * * * ** * ** *** * ** ********* i<=eword; i++)
* * * ** * * ** *
**** **** * * ** *** * **** * * *** *** * * ** ***** = str[i];
**** * ** ** ****** * ** * *** * ** **
* ***** * ** * *
    
* * ** ***** ** ****** * * * * = '\0';
    
*** * * * **** * **** ****** *** * * rev_word);
    
* *** * * *** * ** * * ** 0;
}
answered by (-193 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<string.h>

int main()
{
    int i,j,k,end; //end 要解決最後多出\0的問題
    char a[100];
    scanf("%[^\n]%*c",a);
    j=strlen(a);
    end=j-1;
    for(i=j-1;i>=0;i--)
        {
* * * ** * * *** * *** * ** * ** * * ** ** *** * *** * * ')
* ** * * * * * * ***** * * ** ** *** * * * * * * * **** * ******** * ** *** ***
* * * ** *** * **** ** *** ******* * * *** ** * * **** * *** * * ***** * * * * * *** *** * * ** * * ** * * ***** ** *
****** * ** *** **** * ** * ****** *** * ** *** ** ** * * * * * ** ** * ***** * ** * * * * ****** ** ** *** * * ** *** ****** *** *
* ** * ** * ***** *** * * * * **** *********** **** * **** * * ** *** * * *** ** * * ** ** ** * * * ** *** * * * * * * *** * *** ***** * * ** *
********* *** * * ** * * *** * * * * * *** * * * * * ** ***** *** *** * *** * * * * ** * * * * *** **** ***
* * ** * **** ** * * * *** * **** * ** ** *** *** ** * * * * * ***** *** ** ** ** * * * * *** ** *** ** * ");
* * * * * * * ** * * ** ** ** * * * *** * * * * *** ** * * * * * * ** **** *** * * * * * *** * * * **
***** * * ** **** ** ** * *** ****** ***** * *** * **** ** ** * * * * * *
** * * *** * ** * ** ** * ** * **** * * * * * ****** ** * * * if(i==0)
* * *** *** * *** ** * * ** ***** ** * ****** ** ** ** * **** *** * * * * ****** ** *** **
* ** * * * *** ****** *** *** * * **** ** * **** * * * ** ** ** * **** * *** ** * * * ** * * ***** * *** * ** * *** ** ***** ***
**** * ** * ** *** * * ** * ** * * ** ******* *** ** ** * ****** ** *** * ********** * * *** *** *** * ** *** * * *
* ** ** * ** ** ** ** *** ** *** ** * *** *** **** ** * **** * ** * * * * ****** * ****** * **** * **** ** *** * * **** *** *** * * * *** * * * * * **** * **** **
*** * *** * ***** *** * ** * * * ****** ** ** * *** * * ** * * ***** * * *** * * * *** * *** ****** ** * * * * * ** ********

**** * ** *** * **** *** *** *** * * ** ** ** * **** * * ***** * *** * * ** **** *** * **
        }

return 0;
}
answered by (-301 points)
edited by
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include <string.h>
int main()
{
** *** ******* ** *** * * *a[100]={};
    char b[1000];
* **** *** ** ** ** * ** * * *** ** *
    int i=0,j=0,n;
* * ** * *** * * * * *
** ** * * * * ** ***** * * ** * ******
** ** ** * ** * ** * ** * ** *** * * ****** ****
* * *** **** * * ** * ** ****** * ** ** *********** ** * * **** **
****** *** **** ** ** *** * *** ** * * * * * * * *** * * **** ****** ** *
* * * ** * * *** ** **** * * * **** *** * ** * ** **
****** * * * * * ***** **** ** ** ** ** **** *
*** ** * * ** * * *** ** * ** * * * * if(b[i]=='\n'){
** * * *** ** ** * *** * ** ** * ** * *** * * ** *** **** ** * *
* *** ***** ** * * * ** * * * ** *** * ** *
    }
* ** ** * * * ** * * ** ** *** **
*** ******* * ** * ** ** * ** **** * * ****** * * * *** ** * ****** * * ** *** *** *** * ** * ",a[j]);
    }
** *** **** ** ** **** *** * * ** **
}
answered by (-329 points)
edited by
0 0
prog.c:2:1: warning: return type defaults to 'int' [-Wimplicit-int]
 main()
 ^~~~
prog.c: In function 'main':
prog.c:8:11: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
     for(k=strlen(a);k>=0;k--){
           ^~~~~~
prog.c:8:11: warning: incompatible implicit declaration of built-in function 'strlen'
prog.c:8:11: note: include '<string.h>' or provide a declaration of 'strlen'
0 0
#include<stdio.h>
#include <string.h>
int main()
{
    char *a[100]={};
    char b[1000];
    fgets(b,1000,stdin);
    int i=0,j=0,n;
    n=strlen(b);
    for(i=0;i<n;i++){
        if(b[i]==32){
            b[i]='\0';
            a[j]=&b[i+1];
            j++;
        }
        else if(b[i]=='\n'){
            b[i]='\0';
        }
    }
    for(j=j-1;j>=0;j--){
                printf("%s ",a[j]);
    }
    printf("%s",b);
}
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
int main(void)
{
    char str[100];
    int i,j;
***** * * * * * ***** * * *** * * *
    int n = strlen(str);
    for(i=n-1;i>=0;i--)
    {
** * ** *** *** * ** * * *** * ** **** * ** ' ')
** * ** ** * * ** * * * ** *
* ** **** ***** * ** * *** ** ** ** ** * ******* * ** *** * ** ** **** **** ***
******** ** * ***** * **** * ******* ** * * ** * * * * * * **** * ** ** *
* * * * ** * * * ** ** ** ** * ** *** * ** * *** * ** * **** *** **** **** **** ** ** * * * * * * *** * * *
* ** * * * **** ***** * ** * *** * *** ** * ** * * * * *** * *** *
* * *** * * ** * ** * ** * * ** * * * *** * ******** * * * * ** **
** **** * * * * *** ** * *** * ** * *** *** ** ** ****** * ** * * * * ");
** * ** * ***** * * * *** * * * *
* ** ** * * * * **** ** * ** ****** ** * * * * ***
* * * * * ** ** * ** * * * * * **
*** * ** * * ** * * **** * * *** * * * *** * * * * *** *
** *** ** * *** **** *** * * * *** *** ** ***** * * ** ** *
* * **** * * * ** * * * * ***** ** * * * * * * * *** * ** * *** ** * * * * * ***** ** ** * **
** ** * ******** ** ** * ** * **** * ** * ** * ** ** *** * *
** **** ** ** * *** ** *** * * ** *** * * ** * ***
    }
    return 0;
}
answered by (-281 points)
edited by
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 0
prog.c: In function 'main':
prog.c:7:20: warning: format '%c' expects a matching 'char *' argument [-Wformat=]
     scanf("%[^\n]*%c",str);
                    ^
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>

int main()
{
* * ******* * * ** str[999],strR[999];
    int i,j;
** ** ** * ** * **** * * * * * * * ***** *
* * * *** * * * * * n=strlen(str);
    for (i=n;i>=0;i--)
    {
* ** * *** **** ** * * **** (str[i]==' ')
** ** *** **** ** ** * * ****** * *** *
*** *** *** ** ** * ** * * * *** * ** * ********* * * (j=i+1;j<n;j++)
* *** * ** * * * * * ** *** * * * *** * ** ** * *** *
* ** * *** * * * * * * * * ** * *** * * * *** * * ** ******** **** **** * * * * ** **** **
* ** * * ***** *** ** * ** * * ******* * * *** * ** ** * **** *
* * ***** * * * * *** *** * * * ** ** * **** ** * * ** * * * **** ");
* *** * ** * **** * **** ********* * * *** ** * *************** ** ** *** * ** *
* * *** * **** * ** * * ** * * * *
* * * *** * *** *** * ** * * ** *** * * if (i==0)
*** ** * ** ****** ******** **** ****
** ****** **** ** * * **** *** * * * * ******* ** * ** * * ***** * *** * * (j=i;j<n;j++)
* ****** ** * ******* ***** * * * * ** ** * * *** * *** *** * * ***** * * ***** ** * ******
*** * * ** * *** ****** * * ******
    }
* ***** * * * * * * * ** *** 0;
}
answered by (-249 points)
edited by
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 0
prog.c: In function 'main':
prog.c:10:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'size_t {aka long unsigned int}' [-Wformat=]
     printf("%d\n",strlen(str));
              ^
0 0
prog.c: In function 'main':
prog.c:10:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'size_t {aka long unsigned int}' [-Wformat=]
     printf("%d\n",strlen(str));
              ^
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>

int main()
{
* ***** ** ** *** * array[1000];

* ** ** * *** ** ** *** i = 0;

* * ** **** ******* ** *** ** j = 0;

** * **** * ** ** * **** * 1000, stdin);
* ** * * ** * * ********* * * * * array);
** ** * * * ** ***** ** len = strlen(array);

*** **** * * * * ** ** * = len - 1; i >= 0; i--)
    {
* * ** **** * * * * * * * ** * * * ** * * **** == ' ')
* * *** * * * * ** * **** *** * * ** **
* ***** ** ** * * * **** ** **** * * * **** * * *** * * * * * ** ***** ** = i + 1; j < len; j++)
** ** * *** * ****** *** * ****** ** * * * * ** *** ****** **
* **** ** ** ** * * **** ** ** * * * ***** ** ** * ***** * ** * * *** * ** * ** * * array[j]);
**** * * *** ** ** * * ** * * ** ** * * * ** * ** * * ** * ** **

* * * * *** * * * * * * *** *** ** * * ** * * *** * * = i;

* * * * * * ** * * * * *** *** *** ** * * * * * * ");

* ** * *** * * ** ***** * *** * * *** *** * **** ** ****** = i ;
** ** * * ** **** ** * ***** * ** * ***
* * * * * ** **** **

* *** * ** * * * *** * * ** = 0; i < len; i++)
    {
** * ** ** *** ***** * ** ** * * * * * *** **** * ** ** array[i]);
* * * ***** * * * * * *
}
answered by (-127 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>

int main()
{
*** ** * **** * * *** array[1000];

***** * * * ** * * i = 0;

* * * * * * ** j = 0;

** ** * * ********* * ***** ***** 1000, stdin);
* * ***** * ** *** * ** * ** * ** ** * array);
****** * *** * * * * * len = strlen(array);

**** ** * * *** * * * = len - 1; i >= 0; i--)
    {
*** * ***** *** ****** *** ****** **** ** *** * * == ' ')
* * ** * * ** ** *** **** * * * * **** * *** *
* * * **** * ** * * * * * * * * *** **** ******* * * ***** * *** = i + 1; j < len; j++)
********* ** * * *** ** * * * ** ** ** * * * ** * * * * * *****
* * * * ** ** * * * * ***** ** * * ****** ** ******* * * ** ** * ** *** * * * *** *** ** *** * * array[j]);
* * ** ** *** ******* ** **** * ** ** * ** ** ** * **

**** * *** * ****** * *** ** * *** * * * ** * * ** * * ** = i;

***** *** * *** * ** * ** *** ** * * * * ** ** **** ** ** ");

* ** ** * * ** ** ***** ** * ** * * * * *** * **** * **** = i ;
**** ** ** *** ****** * * *** * **** * * *** *
*** * ** * * * * ** * *

* * ** * *** ******* * = 0; i < len; i++)
    {
* * * * * * **** *** *** * * ** * * ***** * ** ** array[i]);
** ** * * * ** **
}
answered by (-285 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
* * ** * *** * *** * ** **** a[1000];
** ** ** * ** * * * * * * i,j;
* ** * ****** ** * * *** **** * *
* **** * * ** * ** * len = strlen(a);
** ** * *** *** ** * = len - 1 ; i >= 0 ; i--)
*** *** * * ** ** * *
*** * *** * ** * ** **** * ** ** ** * * ** * == ' ')
** *** * *** ** ** ** * * ** * *** *
* * ** ** ************ * ** ******** * ** * * * * * ***** *** ** ** = i+1 ; j < len ; j++)
* ** * *** *** *** * * **** * * * * ***** ** ** * * ****** ******** * *** ** * * * * * * * * ***
* ** * ** * * ** * * * ****** *** ** * * ** ** *** * ***** * * ** * * * ");
* * ** * * * * ** * * ** ** * *** ** * * *** ** * *** **** = i;
* * *** * *** * *** ** * * * ** * **** * ***
* ** * * * * ****
* * ** * ** ** * = 0 ; i < len ; i++)
* * ** * ** ***
* * ** * * **** ****** *** * ** *** * ** * ****** ** ** *** * * *
    }

* ***** ** * * *** * ** * 0;
}
answered by (-255 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:108.162.241.33
©2016-2025

Related questions

0 like 0 dislike
27 answers
[Exercise] Coding (C) - asked Jan 11, 2018 in Chapter 13: Strings by thopd (12.1k points)
ID: 41439 - Available when: Unlimited - Due to: Unlimited
| 9k views
12,783 questions
183,442 answers
172,219 comments
4,824 users