uva 10800 (Not That Kind of Graph)



Algorithm used : 2D String. I enjoyed solving this problem

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;


int main(){
    char graph[102][55];
    int testCase;
    cin>>testCase;
    for(int t = 1;t<=testCase;t++){
     for(int i=0;i<102;i++){
      strcpy(graph[i],"|                                                   ");
      graph[i][52]='\0';
     }
     
     char input[55];scanf("%s",&input);
     int currentY,maxY,minY;
     currentY = maxY = minY = 50;
     bool simpleFlag = false; 
     
     for(int i=0;i<strlen(input);i++){
       if(input[i]=='C'){
        simpleFlag = true;
        graph[currentY][i+2] = '_';
        maxY = max(maxY,currentY);
        minY = min(minY,currentY); 
       }
       if(input[i]=='F'){
        if(simpleFlag)currentY++;
        graph[currentY][i+2] = '\\';
        maxY = max(maxY,currentY);
        simpleFlag = true;
       }
       if(input[i]=='R'){
        simpleFlag = true;
        graph[currentY][i+2] = '/';
        minY = min(minY,currentY);
        currentY--;
       }
     }
     printf("Case #%d:\n",t);
     for(int i=minY;i<=maxY;i++){
     for(int j=52;j>=0;j--)if(graph[i][j]=='_' || graph[i][j]=='/' || graph[i][j]=='\\'){
      graph[i][j+1]= '\0';
      break;
     }
     cout<<graph[i]<<endl;
     }
     cout<<"+-";
     for(int i=0;i<=strlen(input);i++)cout<<'-';
     cout<<endl<<endl;
    
    
    }
    
    
    return 0;
}

Tagged: , , , ,

One thought on “uva 10800 (Not That Kind of Graph)

  1. UVa Solutions By Volumes « exponential fun November 25, 2012 at 4:21 pm

    […] uva 10800 (Not That Kind of Graph) uva 10803 (Thunder Mountain) uva 10852 (Less Prime) uva 10878 (Decode the tape) uva 10879 (Code Refactoring) […]

Did it help you ....?