给定一个长度为偶数位的0,1字符串,请编程实现串的奇偶位互换。
输入
输入包含多组测试数据。
输入的第一行是一个整数C,表示有C测试数据。
接下来是C组测试数据,每组数据输入均为0,1字符串,保证串长为偶数位(串长<=50)。
输出
请为每组测试数据输出奇偶位互换后的结果,每组输出占一行。
样例输入 Copy
2
0110
1100
样例输出 Copy
1001
1100
要求利用数据结构中的串来解决
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
8条回答 默认 最新
- 伍六七0804 2022-10-21 14:06关注
获得0.75元问题酬金 #include "stdio.h" #include "string.h" #include "stdlib.h" #define MAX_STRING_SIZE (50) typedef struct { char ch[MAX_STRING_SIZE]; int length; }String; typedef struct slist { String str; struct slist * next; }str_list; int main() { int c = 0; str_list * head = NULL; str_list * end = NULL; str_list * new = NULL; scanf("%d", &c); for(int i = 0; i < c; i++) { new = (str_list *)malloc(sizeof(str_list)); memset(new, 0, sizeof(str_list)); scanf("%s", new->str.ch); new->str.length = strlen(new->str.ch); if(end != NULL) { end->next = new; end = new; }else{ end = new; head = end; } } str_list * mov = head; while(mov != NULL) { for(int i = 0; i < mov->str.length; i++) { printf("%c", mov->str.ch[i] == '1'?'0':'1'); } printf("\n"); mov = mov->next; } return 0; }
解决 2无用
悬赏问题
- ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
- ¥15 安装quartus II18.1时弹出此error,怎么解决?
- ¥15 keil官网下载psn序列号在哪
- ¥15 想用adb命令做一个通话软件,播放录音
- ¥30 Pytorch深度学习服务器跑不通问题解决?
- ¥15 部分客户订单定位有误的问题
- ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
- ¥15 Bug traq 数据包 大概什么价
- ¥15 在anaconda上pytorch和paddle paddle下载报错
- ¥25 自动填写QQ腾讯文档收集表