poj 1488 TEX Quotes rewriting double quotes (☆☆☆☆☆)

http://poj.org/problem?id=1488

I have done a similar, but also to modify the double quotes.

To use this title to read the entire line, I used to use gets () function, of course, there are other functions get (cin, string s), cin.getline (charArray, max_length, '\ n'). But sometimes error-related with line breaks can occur when doing string problem, can not understand!

Sample Input

"To be or not to be," quoth the Bard, "that
is the question".
The programming contestant replied: "I must disagree.
To `C' or not to `C', that is The Question!"

Sample Output

``To be or not to be,'' quoth the Bard, ``that
is the question''.
The programming contestant replied: ``I must disagree.
To `C' or not to `C', that is The Question!''

 

Source Code
#include <stdio.h>
#include <string.h>


const int N = 1000;
int main(){
	int i,j,cnt=0;
	char src[N],dst[N];
	while(gets(src)){

		for(i=j=0;i<strlen(src);i++){
			if(src[i]!='"'){
				dst[j++]=src[i];
			}
			else {
				cnt=(cnt+1)%2;
				if(cnt){
					dst[j++]='`';
					dst[j++]='`';
				}
				else{
					dst[j++]='\'';
					dst[j++]='\'';				
				}
			}
		}
		dst[j]='\0';
		printf("%s\n",dst);
	}
	return 0;
}

Reproduced in: https: //www.cnblogs.com/pcwl/archive/2011/04/26/2029717.html

Guess you like

Origin blog.csdn.net/weixin_34253126/article/details/92846580