Uva--10361 (字符串处理)
2014-05-29 17:22:16
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=15&page=show_problem&problem=1302
题意:简单题,处理一下字符串即可,需要注意的是输入格式。
HUSTOJ提供了Hint,我用的是逐个如入char的方法
Hint:when u read a line of string after an int, u can use following codes, like scanf("%d",&t);getchar();gets(str); or string str; cin>>t;getchar();getline(cin,str); or u may read some unexpected words
#include <cstdio> #include <stdio.h> #include <string.h> #include <cstring> #include <iostream> #include <fstream> using namespace std; const int maxn = 100; int main(){ char l1[maxn + 5],l2[maxn + 5]; int n,len_l1,f[4]; scanf("%d",&n); getchar(); while(n--){ int cnt = 0; len_l1 = 0; char t; while(scanf("%c",&t) == 1){ if(t == '\n') break; if(t == '<' || t == '>'){ f[cnt++] = len_l1; } else{ l1[len_l1] = t; printf("%c",t); } ++len_l1; } puts(""); while(scanf("%c",&t) == 1){ if(t == '\n') break; else if(t != '.'){ printf("%c",t); } } for(int i = f[2] + 1; i < f[3]; i++) printf("%c",l1[i]); for(int i = f[1] + 1; i < f[2]; i++) printf("%c",l1[i]); for(int i = f[0] + 1; i < f[1]; i++) printf("%c",l1[i]); for(int i = f[3] + 1; i < len_l1; i++) printf("%c",l1[i]); puts(""); } return 0; }