UVA Solution 444 – Encoder and Decoder – Solution in C, C++

UVA Online Judge Solution 400 | Volume 4
UVA Problem Link – https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=6&page=show_problem&problem=385

Problem Name: 444 – Encoder and Decoder
Problem Number : UVA – 444 – Encoder and Decoder
Online Judge : UVA Online Judge Solution
Volume: 4
Solution Language : C,C plus plus

UVA Online Judge Solution, UVA OJ Solution list, UVA Problems Solution, UVA solver, UVA all problem solution list

UVA Solution 444 – Encoder and Decoder Code in CPP:

#include <stdio.h>
#include <string.h>
int main() {
char
str[999];
char
ascii[128] = {};
int
i;
ascii[' '] = ascii['!'] = ascii[','] = 1;
ascii['.'] = ascii[':'] = ascii[';'] = 1;
ascii['?'] = 1;
for
(i = 'a'; i <= 'z'; i++)
ascii[i] = 1;
for
(i = 'A'; i <= 'Z'; i++)
ascii[i] = 1;
while
(gets(str)) {
int
i, j, tmp, idx = 0;
char
code[999];
if
(str[0] >= '0' && str[0] <= '9') {
tmp = 0;
for
(i = strlen(str)-1; i >= 0; i--) {
tmp = tmp*10 + str[i]-'0';
if
(ascii[tmp]) {
code[idx++] = tmp;
tmp = 0;
}
}

if
(ascii[tmp]) {
putchar(tmp);
tmp = 0;
}
}
else {
for
(i = strlen(str)-1; i >= 0; i--) {
while
(str[i]) {
code[idx++] = str[i]%10+'0';
str[i] /= 10;
}
}
}

for
(i = 0; i < idx; i++)
putchar(code[i]);
puts("");
}

return
0;
}

Tags: UVA Online Judge Solution, UVA OJ Solution list, UVA Problems Solution, UVA solver, UVA all problem solution list, UVA 444 code in C, UVA Encoder and Decoder  code in C++, UVA 444 solution in C, UVA Encoder and Decoder solution

By Maniruzzaman Akash

Maniruzzaman Akash is a freelance web developer with most popular Laravel PHP frameork and Vue JS

Leave a Reply

Your email address will not be published. Required fields are marked *