給定n對詩句,每對詩句的第一句為s1<s2>s3<s4>s5的形式(si表示那是個字串,可包含空格),我們所要做的就是把第一句<>去掉,然後第二句的"..."換成"s4s3s2s5"即可。
想法:
讀取每個si的時候一定要以'<'或'>'作為分隔點,因為測資不一定是以空格隔開。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
using namespace std; | |
void l1 (char line[], char s[][1000]) | |
{ | |
int i,j; | |
for (i=0; line[i]!='<'; i++) printf("%c",line[i]); | |
for (i++,j=0; line[i]!='>'; i++,j++) s[2][j] = line[i]; | |
s[2][j] = '\0'; | |
for (i++,j=0; line[i]!='<'; i++,j++) s[3][j] = line[i]; | |
s[3][j] = '\0'; | |
for (i++,j=0; line[i]!='>'; i++,j++) s[4][j] = line[i]; | |
s[4][j] = '\0'; | |
for (i++,j=0; line[i]; i++,j++) s[5][j] = line[i]; | |
s[5][j] = '\0'; | |
printf("%s%s%s%s\n",s[2],s[3],s[4],s[5]); | |
} | |
void l2 (char line[], char s[][1000]) | |
{ | |
int i,j; | |
for (i=0; line[i]!='.'; i++) printf("%c",line[i]); | |
printf("%s%s%s%s\n",s[4],s[3],s[2],s[5]); | |
} | |
int main() | |
{ | |
// freopen ("input.txt","rt",stdin); | |
int N; | |
char line[10000],s[6][1000]; | |
scanf("%d",&N); | |
getchar(); | |
while (N--){ | |
gets(line); | |
l1 (line, s); | |
gets(line); | |
l2 (line, s); | |
} | |
return 0; | |
} |
沒有留言:
張貼留言