UVA10361 - Automatic Poetry
来源:互联网 发布:联通网络测速 编辑:程序博客网 时间:2024/04/27 15:11
问题描述
第一行输入字符串形势如同s1<s2>s3<s4>s5,第二行输入的字符串中,将s2和s4互换,并输出("<>"不输出)。
思路
将字符串分隔存储,然后进行处理,看懂题意并不难,难得是如何让自己写的代码能够简洁明了。
代码
#include <iostream>#include <string>#include <cstdio>#include <cstring>const int maxn=120;using namespace std;int main(){ int n,i,j; char s1[maxn],s2[maxn],s3[maxn],s4[maxn],s5[maxn],s[maxn],sn[maxn]; cin>>n; getchar(); while(n--) { int a,b,c,d,e; a=b=c=d=e=0; memset(s,0,sizeof(s)); memset(sn,0,sizeof(sn)); gets(s); gets(sn); for(i=0;s[i]!='<';i++) s1[a++]=s[i]; s1[a]='\0'; for(j=i+1;s[j]!='>';j++) s2[b++]=s[j]; s2[b]='\0'; for(i=j+1;s[i]!='<';i++) s3[c++]=s[i]; s3[c]='\0'; for(j=i+1;s[j]!='>';j++) s4[d++]=s[j]; s4[d]='\0'; for(i=j+1;s[i]!='\0';i++) s5[e++]=s[i]; s5[e]='\0'; cout<<s1<<s2<<s3<<s4<<s5<<endl; sn[strlen(sn)-3]='\0'; cout<<sn<<s4<<s3<<s2<<s5<<endl; } return 0;}
0 0
- uva10361 - Automatic Poetry
- UVA10361- Automatic Poetry
- UVa10361 Automatic Poetry
- UVA10361 - Automatic Poetry
- uva10361 - Automatic Poetry
- UVA10361 - Automatic Poetry
- UVa10361 - Automatic Poetry
- uva10361 Automatic Poetry
- UVA10361 - Automatic Poetry
- UVA10361 - Automatic Poetry
- UVa10361-Automatic Poetry-字符串-难度1
- uva10361 Automatic Poetry(getline 的用法)
- Automatic Poetry
- Automatic Poetry
- Automatic Poetry
- Automatic Poetry
- Automatic Poetry
- Automatic Poetry
- 9.Web 服务器
- Python网络通信之socket模块(一)关于套接字
- 控制台警告“"This application is modifying the autolayout engine from a background thread, which can lead”
- 定义一个字符数组,在其中找出指定的字符,并且返回他的索引值
- LeetCode 221 Maximal Square
- UVA10361 - Automatic Poetry
- scala进阶21-actor之消息传递
- 【模拟】Codeforces 710C Magic Odd Square
- 126. Word Ladder II(bfs+dfs)
- lda主题模型
- 【动态规划】【最短路】Codeforces 710E Generate a String
- 357. Count Numbers with Unique Digits
- 绝对定位下的margin
- Java中的异常理解