0 like 0 dislike
10.6k 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 | 10.6k views

29 Answers

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

int main()
{
*** * ***** * * * *** i,o,txtlen, end;
** ** ** * *** * * * * *** sentence[100];
** **** ** ** * * **** * ** * ** * *** *** * ** ** sentence);

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

* *** ****** **** * ** * **** i>=0; i--)
* ** ** *** * * ** **
* * * ** ** ** ** *** *** *** **** ** * * (sentence[i]==' ')
* *** **** * * * * * * ** ** ** ** ** *** *
* ** * * * * * * **** ****** ****** * ********* ***** ** *** *** * o<=txtlen; o++)
**** ** **** * ** * * * ** **** ** ***** * ** ** ** * * * ** ** * *** * * * ** ** * * * * * **** * * *
** * * ** **** * ** * **** ** * * ***** ** * ** **** = i-1;
* ** ** ** * *** * *** * *** * ** * * * ** **** *** * * ** * * * ");
* ** ** * ** ** ** ** * ** * **

    }
*** * ** * * * i<=txtlen; i++)
* * **** * * ***** ** **** * * * ** * ** * ** * * * sentence[i]);

}
answered by (-336 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 c,d,e;
    char a[100];
* * * * ** *** * * ******* ** * **** **
*** * ** ** ** **** * **
* * * **** * * ** * * ** *** * ** ** *** ** * *
** * ** * * * **** ***** * * * ****
*** *** ***** * *** * * * * ****** * * *** ** * * * ** * * * * * ** * '){
** **** * ** * * ** * **** * * * ** ** * *** * ** * * * * * * * * * * ** ** * * * ** * ***
*** * * * ** ** * * * * * * * * * ** ***** * *** * * * ** * **** * **** * *** * * ****** * * * * ** *** * ** * * * * sentence
* * * * ***** *** ** * * **** * * ******* * * * *** * ** **** ****** * **** ** * *** * * *
* ** * ******* * * * * ** *** * ** *** * * ** * ** * *** ** * *** * **** * * * **** ** *** ");
** *** **** * *** * * * ** ** ** ** **** * *** ** * * ** * * * * *** *** ** **** * *
***** ** *** * ** * *** * * ** * ******* * *** * * * * *** * ** **
    }
* *** ** * ** * * ** * ** ** ***
*** * ** *** ** ** * *** * ****** *** * ** **** ** * * ** * * *
    }
    return 0;
}
answered by (-498 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
-----------Re-judge-----------
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()
{
**** ** ** **** * *** * str[1000], reverse[1000];
* ** * * *** ***** * * len, i, index, wordStart, wordEnd;


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

* ** ** * * * * ***   = strlen(str);
* ** * *** * * ***** ** = 0;


**** *** * * * * * ** **** = len - 1;
* ** * * *** ** * ** * **   = len - 1;

* *** * * * * * * ** * * ** > 0)
* ** * ** *** ***

*** *** * * * * *** ** **** * *** ** * ** *** * * * * ** ** == ' ')
* * ** * * ** * ** * * * * * *** **

* *** * * * * * * * **** *** * ****** ***** ** * * ******* * * * = wordStart + 1;
*** *** **** ** * * ** *** ** *** * * ** ** ** ** *** * * ** <= wordEnd)
** * ** ** ** ** * *** ** * * * * **** * **** * *
**** * **** * * ***** *** * * ** * * ** * ** ** * ** *** * * ** * ** * ** * * * *** ** * = str[i];

* * ** ** * *** * * * * * * * * * * * * * ** **** ********* ** *** ** * ****** ** * * * ***
* ** *** * * * * * * *** * * * * * ** * * * * * ** * ** * * * * ** * * *
*** ** * ** ** * ** ** ** * *** * *** * ***
** ** ** *** *** *** *** *** *** * * * * * **** * * * * ** *** = ' ';

* * * * * ** ** ******* ** ** ** ** * * *** * * * *** * ** * ***** = wordStart - 1;
*** ** ** * * ** *** * * **** *** ** * *

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

** * * * ** *** * * *** * * i<=wordEnd; i++)
    {
***** ***** ** * ** * * * *** *** * ** **** * ** * = str[i];
* * * * * * * *** * *** *** ** * * * *
    }


* * ***** * ** **** ****** * *** * = '\0';


* * * * ** **** **** *** ** **** *** * reverse);

** * * ** * ** **** 0;
}
answered by (-196 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: 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=0,j=0;
    char a[100],*b[100];
* * ** * * * * *** * ** *
***** * * * * * * * * * *** *
** * ** * * * ***** * * * * * **
** * *** *** ****** * ***** * ** *** * * * * *** * *** ** ** * *****
** ** ** ** *** ** ** * * * * * ** *** **
*** *** * *** *** * * *** **** * * ****** ** ** ***** ** ** ***** ** ** ** * **
** *** * ** *** **** * ** * ** * * * **** *** *** * * ** * ** *** *** *** ****
* * * * ** *** * * *** *** ** ** ** * ** ***** * * ** **
**** *** * * ** * * * ** * * ** ** *
*** * * * * * * * * ** * ** * ****
    }
**** * * * *** * * ****** ****
* ** * ** ** ** * * * ***** ** ** * ** ** * ******* ",b[i]);
    }
* * * * *** * *** ** **** **** * ** * * **
*** **** * * * * * * * 0;
}
answered by (54 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!
** ** ** *

void reverse(char *first, char *last);
void reverseWords(char *s)
{
** ***** * * * * * * * *first_word = s,*temp = s;
*** **** * *** * * *temp )
******* * * * ***
*** * * * * ** *** ** *** * ** * * * * ** * * *
* * ***** * * ** * * ***** ****** *** * (*temp == '\0')
* ****** ** ** ******* ** *** * * ** * ** ** * * * *** * * * * * **** ** temp-1);   }
** *** * * * ** ** * ** * ** * * * ** *** *** if(*temp == ' ')
**** * ** ********* * **** * ** ******* * *** * * **** * ** * temp-1);
** ** * * * ***** ***** * ** * ** ** *** * * ** * * * * = temp+1;
* **** * * * *** * ** * * ****** *****
**** ******* * * * *
* * * *** * ** * **** ** temp-1);
}
void reverse(char *first, char *last)
{
* * ** *** *** * *** temp;
** * *** ** ** *** * ** * * (first< last)
** * ** **** * * *   temp = *first;
**** * *** *** * ** *** * ** **** ** * * * * * * = *last;
****** *** ** ****** * ******** ** ** ** ***** *** * = temp;
* ** * ***** * * *
}

int main()
{
* * * *** ****** s[100];
* ** * * ** * * *** ***** ***** * ** * s);
* * * * * *** * * *temp = s;
**** ** *** *** ** ***** *** * **
*** * ** *** ** ** ** ** * ** * * * s);
*** * ** * * ** * * ***** ** 0;
}
answered by (-304 points)
edited by
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong 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() {
    char s[1000];
    int len=0,count=0,i,check=0;
    fgets(s,1000,stdin);
    len=strlen(s);
      len++;
    for(;len>0;len--) {
* * * * ****** * * *** * * * * * * ** ***** * ') {
** ** *** *** *** * *** * ** * ** *** * * **** **** *** *** * * ** ** ** {
** * ** *** * ***** ** ** * ** * ** **** *** ** * * ** * **** ***** ** *** ** ** * {
*** * ** * ** * * ** *** * *** * ** **** **** ** * *** **** **** ** * *** * * ** ** * ** * ** ** * *** *
** ** * * ***** ****** *** * *** * ** * * * * * ***** **** * **** ** * * * * *** *
* ** ***** **** ** ** * ** *** * * ** ****** * ** ** * ** ** *** ** * ** ** ** * ** * {
*** * *** **** ** **** *** *** * * **** ** *** * **** * * ***** *** * *** * * * * *** *** * * **** * * ** * **** * * *** ******** s[len+i-2]);
** * * ** * * * ** ** ** * **** * **** * * * * * * ** ** * * * *** * ****
** ** **** ** * * * * * * * *** ** * * **** * ** * * ** * ** ***** * **
* * * ** ***** * * ** ********* *** **** **** ** ** * * * ** ** ** *
        }
* ** * *** *** * ** ** * **** * * * * ** * if(len-2==0) {
** * ** * * * ** * * ** ***** ** * * * *** ** * **** ** ****** * ** ** {
*** *** * ** ** **** * * * ** * ** ****** * ** ** * * * * ** ** * ** * *** * * * ");
***** *** **** *** * *** ** * * * *** * ** ** * * ** *
* ** * ** ** *** **** ** * ** *** * ****** ***** *** {
*** *** ** ** ** ** * **** * * * * ** * ** * * * ***** *** ***** ** * * ** ** * * * * * **** *** ** * * * s[len+i-2]);
*** * **** * * ** *** * *** * * * ***** * *** **** * * * ** ** * ***** *
* * * ***** * ** * *** * * ** * **** *** * ****
* * *** * * ** ** ** * ** * ** * *** *** {
* * * * * * * * * * * ** **** ** ** * ** *** * * *** ** * * ***
***** * * **** *** ** ** *** ***** ** ** ***
    }
}
answered by (-120 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 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
#define MAX_SIZE 100

int main()
{

**** * **** * *** * ***** * str[1000], reverse[1000];
*** ** * * *** * * * len, i, index=0, wordStart, wordEnd;

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

* *** ** *** * * * *****   = strlen(str);


*** * ****** ** **** *** ** * = len - 1;
*** * ***** **** * **** **   = len - 1;

** *** * ** * ** *** * *** * > 0)
    {

* * * ***** ******** * **** ** * * * *** * ***** == ' ')
* * **** * ** ***** * * ** * * ** * ** * **

* *** * ** * ** * * * * **** ***** *** ** ** * ** * ** * * * = wordStart + 1;
* ** ** * * ** ** ** * *** ** ** **** ** *** * * ** * ** ** <= wordEnd)
*** * ** * ** * * ** * *** * **** **** *** *** * * **** * * **
* * *** * * * *** ** * *** * * *** ** * ** *** * ** **** * *** * **** * * = str[i];

* * * ** **** *** ** ** * * ** * ***** * * **** *** * ** * * *** ** * **** *
*** *** ** ** * *** ***** ** * * ********* ** * * ** * * *** * ** * ** ** ***** **
* * *** *** ** * * * * * ** *** ** * * **** * * * * *
** ** ** **** ** * **** * *** * ** * ** ****** *** * *** ** ******** * * *** * **** * = ' ';

**** **** * ** * **** * *** * * * *** *** ** ** ** * * * ** ** = wordStart - 1;
* *** ** **** *** * * *** ***** ***** ** *

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


* ** ***** ** ** *** * * i<=wordEnd; i++)
    {
*** * * *** **** * * * * * * ** *** * ** * ******** = str[i];
* * * ** * * ** * * * * ** ** *** ***** ***
    }

** ** *** * *** ** ******* *** ** = '\0';

* * * **** ** * * ** **** ** reverse);
** * * * * ** *** *** * (i=0;i<strlen(reverse);i++){
* ** * ** *** * * **** ** ***** * * * (reverse[i]=='\n')
* ** * * *** ** **** * ******* * * * * * * ** ** * *** **
* ** * * ** * * * **** **** * *** * *
** ***** *** *** * ** * * * * ******* * ** ** ** * * * ** **** ***** ** * *** * *
* * * ** *******


* * *** ** * * * *** ** 0;
}
answered by (-323 points)
edited by
0 0
prog.c: In function 'main':
prog.c:10:5: 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/ccHXIf7r.o: In function `main':
prog.c:(.text+0x2f): warning: the `gets' function is dangerous and should not be used.
0 0
prog.c: In function 'main':
prog.c:11:5: 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/ccDHB1g4.o: In function `main':
prog.c:(.text+0x30): warning: the `gets' function is dangerous and should not be used.
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(){
** *** * *** *** strSlice[500][50];
** **** * * ** ** ****** i=0;
* *** * ** ** * * * * * *** * *** * * * * * * * EOF){
* *** * ***** *** * * * * ** ** * * * **
* * **** * * **** *
*** ** * ** ***** * flag=1;
* * * * ** ** * ****** * **
* * * * * * * **** * * * * *** * ** ***** * * ***
*** *** ** * ** * * ** ** ** * ** * ** * * * * *** ** ** **** * * ** ****** **
* * ** *** * * * * ** ** * ** ******* * * **** * ** *** * * **** * **
* * *** ** ** * * * * * * *** * * ** ** * *
*** *** * *** * ** * * ** * *** **** printf(" %s",strSlice[i]);
    }
** * * * ****** * * 0;
}
answered by (-116 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: 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>

int main()
{
* * *** ** * ** ****** * str[100];
** * *** **** ** * **** space[100] = {0};
*** ** *** *** * ** * d = 0;
**** *** * * ** * ** i = 0;
* *** * ** *** * * * * ("%[^\n]%*c", str);
  
****** *** ** ** * * ** ****
* * * * *** ** ** *
** * ** * * *** ** * *** ** ** * *** **** (str[i] == ' ') {
* *** *** * *** * * * *** * ** ** * ** * ** * ** * * ** * * * ***** * space position with letters count following
* **** ** * * * * * **** *** *** * *** ** * * ** *** *** **** **** * ** = d;
* ** ** ** * *** * * * ***** * **** ** ** * * *** **** * * = 0;
******* * *** *** * * **** * ** * * * * * else d++;
** * * ** ***** * ** **** * ** ** *****
* * * ****** * ** * *
*** * * *** * ** * * * * words count
* * * * ** *** ** * = d;
* ** *** *** ** * *** now i actually is the length of str
*** ** ** * * **** (int j=i;j>=0;j--){
**** * ****** ** * *** ********** ** *** * * (space[j]>0){
** ** * ** ** * ** ** * ** * * ** **** * * *** ** *** *** ***** (int k=j-space[j];k<j;k++) * ** ** * ** * *** ***
* ** * ** * * ** * *** ** ** * * * * * * ** * ** * * ** **** * (j!=space[j]) printf(" ");
* * * * * ** * *** **** * * ** * * ******** ***
*** ** ** * ** ***** * ** ** ** * * *
* **** * * * * *
* * *** ** * * ** * 0;
}
answered by (12.1k 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:172.69.130.92
©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
| 10.7k views
12,783 questions
183,442 answers
172,219 comments
4,824 users