uva10361--String

本文介绍了一个简单的字符串拼接程序,通过手动逐字符读取并拼接五个字符串,再结合一个额外的缓冲区字符串进行不同顺序的输出。此过程展示了基本的输入输出操作及字符串处理技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

字符串类型的水题

//#define LOCAL #include <stdio.h> #include <string.h> #define MAXN 100 + 10 char s1[MAXN], s2[MAXN], s3[MAXN], s4[MAXN], s5[MAXN]; char buf[MAXN]; int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #endif int cases; char c; int i, j; scanf("%d", &cases); c = getchar();// 消除数字后面的回车 while(cases--) { // 数据初始化 memset(s1, 0, sizeof(s1)); memset(s2, 0, sizeof(s2)); memset(s3, 0, sizeof(s3)); memset(s4, 0, sizeof(s4)); memset(s5, 0, sizeof(s5)); memset(buf, 0, sizeof(buf)); // 数据输入 // 输入s1 c = getchar(); for(i = 0;c != '<';i++) { s1[i] = c; c = getchar(); } // 输入s2 c = getchar(); for(i = 0;c != '>';i++) { s2[i] = c; c = getchar(); } // 输入s3 c = getchar(); for(i = 0;c != '<';i++) { s3[i] = c; c = getchar(); } // 输入s4 c = getchar(); for(i = 0; c != '>';i++) { s4[i] = c; c = getchar(); } // 输入s5 c = getchar(); for(i = 0; c != '\n';i++) { s5[i] = c; c = getchar(); } // 输入buf c = getchar(); for(i = 0; c != '.';i++) { buf[i] = c; c = getchar(); } c = getchar(); c = getchar(); c = getchar(); // 消除两个点和一个换行 // 数据输出 printf("%s%s%s%s%s\n", s1, s2, s3, s4, s5); printf("%s%s%s%s%s\n", buf, s4, s3, s2, s5); } return 0; }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值