poj 1488 TEX Quotes 双引号的改写 (☆☆☆☆☆)

poj 1488 TEX Quotes 双引号的改写 (☆☆☆☆☆)

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

曾经做过一个类似的,也是对双引号进行修改。

这题要使用整行读人,我习惯使用gets()函数,当然也有其他的函数get(cin,string s)、cin.getline(charArray, max_length,’\n’)。但有时做字符串题时会发生与换行符有关的错误,不能理解!

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;
}

转载于:https://www.cnblogs.com/pcwl/archive/2011/04/26/2029717.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/100837.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号