10-3. String reverse order (15) time limit MS Memory limit 65536 KB code length limit 8000 B program standard author Bai Honghuan (Zhejiang University)
Enter a string, reverse the string, and output the string after the reverse order.
Input format:
Enter a non-empty string with a carriage return ending in a row that is not longer than 80 characters long.
Output format:
Prints the string after the reverse order in a row.
Input Sample:
Hello world!
Sample output:
!dlrow Olleh
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void swap (int a,int B,char *a)
{
Char Temp;int i,j;
for (i=a,j=b;i<=j;i++,j--)
{
Temp=a[i];
A[I]=A[J];
A[j]=temp;
}
}
int main ()
{
Char omg[101];
memset (omg,0,sizeof (OMG));
int N;
Gets (OMG);
scanf ("%d", &n);
if (N>=strlen (OMG)) N=n%strlen (OMG);
Swap (0,N-1,OMG);
Swap (N,strlen (OMG) -1,OMG);
Swap (0,strlen (OMG) -1,OMG);
Puts (OMG);
return 0;
}
Programming Ability Test Study 10-3. String reverse order (15)