UVA 272 problem solution in C, C++ language (TeX Quotes) - Online Judge Solution

Latest

It is a free Online judges problems solution list. Here you can find UVA online Judge Solution, URI Online Judge Solution, Code Marshal Online Judge Solution, Spoz Online Judge Problems Solution

Saturday, March 5, 2016

UVA 272 problem solution in C, C++ language (TeX Quotes)

UVA 272 problem solution in c language(TeX Quotes)


UVA Online Judge Solution 400 | Volume 4

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 272 problem solution in C, C++ language (TeX Quotes)

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

1 comment:

  1. Hi, I also code this solution, for people that unknown about char array an gets function, enjoy!

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

    ReplyDelete