UVaOJ_Problem10361_Automatic Poetry

来源:互联网 发布:淘宝app五星评价 编辑:程序博客网 时间:2024/05/20 21:20
//字符串处理,没什么技术含量,多注意处理下输入时的空格、换行就行了#include<stdio.h>#include<string.h>#include<iostream>using namespace std;int main(){//freopen("TestData.txt","w",stdout);int N,k,BrCnt,BrPos[4],DotFlag,DotPos;char TempCh,Sen1[1000],Sen2[1000];scanf("%d",&N); //scanf读完N之后会把\n留在输入缓冲区 getchar();//吃掉回车 for(int caseNo=1; caseNo<=N; caseNo++){k=0; BrCnt=0;while( (TempCh = getchar())!='\n'){Sen1[k]=TempCh;if(TempCh=='<'||TempCh=='>') BrPos[BrCnt++]=k;k++;}Sen1[k]=0;k=0; DotFlag=0;while((TempCh = getchar())!='\n'){Sen2[k]=TempCh;if((TempCh=='.') && (DotFlag==0)); {DotPos=k; DotFlag=1;}k++;}Sen2[k]=0;for(int ii=0; ii<strlen(Sen1); ii++){if( (Sen1[ii]!='<') && (Sen1[ii]!='>')) printf("%c",Sen1[ii]); }printf("\n");for(int jj=0; jj<strlen(Sen2); jj++){if(Sen2[jj]!='.') printf("%c",Sen2[jj]);else{for(int ll=BrPos[2]+1; ll<BrPos[3]; ll++) printf("%c",Sen1[ll]);for(int ll=BrPos[1]+1; ll<BrPos[2]; ll++) printf("%c",Sen1[ll]);for(int ll=BrPos[0]+1; ll<BrPos[1]; ll++) printf("%c",Sen1[ll]);for(int ll=BrPos[3]+1; ll<strlen(Sen1); ll++) printf("%c",Sen1[ll]);jj=jj+3;}}printf("\n");}return 0;}

0 0
原创粉丝点击