UVA Solution 200 - Rare Order - Solution in C++ | Volume 2 - 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

Sunday, April 30, 2017

UVA Solution 200 - Rare Order - Solution in C++ | Volume 2

UVA Solution 200 - Rare Order - Solution in C++ | Volume 2


UVA Online Judge Solution 200 - Rare Order| Volume 2
UVA Question Link - https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=4&page=show_problem&problem=136

Problem Name: Rare Order
Problem Number : UVA - 200
Online Judge : UVA Online Judge Solution
Volume: 2
Solution Language : C plus plus

UVA Solution 200 Code in CPP:


#include<stdio.h>
#include<string.h>
int Map[26][26], App[26], Used[26];
void compare(const char *A, const char *B) {
 while(*A && *B && *A == *B) {
  A++;
  B++;
 }
 if(*A && *B) {
  char cA, cB;
  cA = *A - 'A', cB = *B - 'A';
  Map[cA][cB] = 1;
  App[cA] = 1, App[cB] = 1;
 }
}
int main() {
 int n = 0, i, j;
 char *pre = new char[255];
 char *cur = new char[255];
 memset(Map, 0, sizeof(Map));
 memset(App, 0, sizeof(App));
 memset(Used, 0, sizeof(Used));
 
 scanf("%s", pre), n++;
 while(scanf("%s", cur) == 1) {
  if(cur[0] == '#') break;
  compare(pre, cur);
  char *tmp;
  tmp = pre, pre = cur, cur = tmp;
  n++;
 }
 while(1) {
  for(i = 0; i < 26; i++) {
   for(j = 0; j < 26; j++)
    if(Map[j][i])
     break;
   if(j == 26 && App[i]) break;
  }
  if(i == 26) break;
  App[i] = 0;
  for(j = 0; j < 26; j++) Map[i][j] = 0;
  printf("%c", i+'A');
 }
 if(n == 1) printf("%c", pre[0]);
 puts("");
    return 0;
}

No comments:

Post a Comment