第一种翻转
Sample Input
1
3
I am happy today
To be or not to be
I want to win the practice contest
Sample Output
I ma yppah yadot
oT eb ro ton ot eb
I tnaw ot niw eht ecitcarp tsetnoc
int main()
{
int m,j;
char b[1000];
scanf("%d",&m);
getchar();
while (m--){
scanf("%d",&j);
getchar();
while (j){
scanf("%s",b);
int len = strlen(b);
for (int i = len-1;i >= 0;i--){
printf("%c",b[i]);
}
if (getchar() == '\n')
{
j--;
printf("\n");
}
else
printf(" ");
}
if (m)
printf("\n");
}
return 0;
}
第二种翻转
Input:
english is very interesting
Output:
interesting very is english
void swap_str(char str[],int start,int end)
{
int low = start;
int high = end;
while (low < high){
// swap(str[low], str[high]);
char temp = str[high];
str[high] = str[low];
str[low] = temp;
low++;
high--;
}
}
void rev(char str[]){
int len = strlen(str);
swap_str(str,0,len-1);
int i2 = 0;
int i3 = 0;
for(int i1 = 0; i1 < len;i1++){
if ((str[i1] == ' ')||(i1 == len-1)){
i3 = i1;
swap_str(str,i2,i3-1);
i2 = i3+1;
}
}
}
int main()
{
char s[1000],c;
int i = 0;
//scanf("%s",s);
//int len = strlen(s);
/*while (getchar() != '\n'){
}
printf("%s\n",s);*/
/*scanf("%s",s);
printf("%s\n",s);*/
while ((c=getchar()) != '\n')
s[i++] = c;
s[i] = '\0';
rev(s);
printf("%s",s);<pre name="code" class="cpp"> return 0;
}