zoukankan      html  css  js  c++  java
  • 奇偶位互换

    Problem Description
    给定一个长度为偶数位的0,1字符串,请编程实现串的奇偶位互换。
     
    Input
    输入包含多组测试数据;
    输入的第一行是一个整数C,表示有C测试数据;
    接下来是C组测试数据,每组数据输入均为0,1字符串,保证串长为偶数位(串长<=50)。
     
    Output
    请为每组测试数据输出奇偶位互换后的结果;
    每组输出占一行。
     
    Sample Input
    2
    0110
    1100
     
    Sample Output
    1001
    1100
     
     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 int main(){
     5     int T;
     6     char s[51];
     7     int length;
     8     char temp;
     9     int i;
    10     
    11     scanf("%d",&T);
    12     
    13     while(T--){
    14         scanf("%s",s);
    15         length=strlen(s);
    16         
    17         for(i=0;i<length-1;i+=2){
    18             temp=s[i];
    19             s[i]=s[i+1];
    20             s[i+1]=temp;
    21         }
    22         
    23         printf("%s
    ",s);
    24     }
    25             
    26     return 0;
    27 }
  • 相关阅读:
    ado.net
    sql基础
    css样式
    HTML基础加强
    socket网络编程
    网络聊天室
    多线程
    WinForm基础
    使用Maven插件(plugin)MyBatis Generator逆向工程
    SpringBoot使用thymeleaf时候遇到无法渲染问题(404/500)
  • 原文地址:https://www.cnblogs.com/zqxLonely/p/4055053.html
Copyright © 2011-2022 走看看