UVA 272 problem solution in c language(TeX Quotes)
UVA Online Judge Solution 400 | Volume 4
UVA Problem Link - https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=4&page=show_problem&problem=208
Problem Name: 272 Tex Quotes
Problem Number : UVA - 272 Tex Quotes
Online Judge : UVA Online Judge Solution
Volume: 2
Solution Language : C, C plus plus
UVA Solution 272 Code in C:
#include<stdio.h> int main( ){ char ch; long int total; while(scanf("%c", &ch) != 1){ if(ch == '"'){ total++; if(total % 2 == 1){ printf("``"); }else if(total % 2 == 0){ printf("''"); } }else{ printf("%c", ch); } } }
UVA Solution 272 Code in C++:
#include<stdio.h> int main() { char s[10001]; int i, flag = 0; while(gets(s)) { for(i = 0; s[i]; i++) { if(s[i] == '\"') { if(!flag) { printf("``"); } else printf("''"); flag = 1 - flag; } else putchar(s[i]); } puts(""); } return 0; }
Tags: UVA Online Judge Solution, UVA OJ Solution list, UVA Problems Solution, UVA 272 code in CPP, UVA 272 solution, UVA 272 code in C++, UVA 272 solution in C
Hi, I also code this solution, for people that unknown about char array an gets function, enjoy!
ReplyDelete#include
using namespace std;
int main() {
string s;
while(getline(cin,s)){
for(int i=0;i<s.length();i++){
bool open=true;
if(s[i]=='"'&&open){
cout<<"``";
open=!open;
}else if(s[i]=='"'&&!open){
cout<<"''";
open=!open;
}
else{
cout<<s[i];
}
}
cout<<endl;
}
}