关于句子翻转的几个问题

第一种翻转

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;
}

 
 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值