706 - LCD Display

All about problems in Volume 7. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

nekizalb
New poster
Posts: 2
Joined: Wed Jan 28, 2009 11:32 pm

Re: 706 - LC-Display

Post by nekizalb » Wed Jan 28, 2009 11:37 pm

Hello Everyone. I could really use some help here. I'm getting a runtime error from the judge, but I don't get one personally. The programming challenges judge gives me a wrong answer. I'm really confused.

Code: Select all

error fixed
I've made sure that I have spaces up until the end of each line. I've tried with new lines after the last number and without. I'm just not having any luck. I'd appreciate any help you can provide. Thanks!
Last edited by nekizalb on Thu Jan 29, 2009 8:26 pm, edited 1 time in total.

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: 706 - LC-Display

Post by mf » Wed Jan 28, 2009 11:47 pm

vahid sanei just a few posts above already mentioned a potential trick in this problem - there may be leading, trailing spaces and more than one space between the numbers on each line in the input. I think your code can throw an unhandled exception in these cases, which is reported to you as a runtime error.

nekizalb
New poster
Posts: 2
Joined: Wed Jan 28, 2009 11:32 pm

Re: 706 - LC-Display

Post by nekizalb » Thu Jan 29, 2009 8:26 pm

Ok, Thanks a lot. That got programming-challenges to give me a solved. I got a time limit error from the judge here, but I got the result i needed for class. Thanks for the help.

marcosroriz
New poster
Posts: 1
Joined: Mon Apr 20, 2009 7:58 pm

Re: 706 - LC-Display

Post by marcosroriz » Mon Apr 20, 2009 8:01 pm

Guys I keep getting WA, and I tested for every single case and It's working. Can any 1 here helps me identify whats wrong?

Code: Select all

#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

void desenha(int s, int digitos, int vetor[]) {
	int linhas = (2 * s) + 3;
	int colunas = digitos * (s + 2) + (digitos - 1);
	
	string matriz[linhas][colunas];
	for (int i = 0; i < linhas; i++) {
		for (int j = 0; j < colunas; j++) {
			matriz[i][j] = " ";
		}
	}
	
	int colunaAtual = 0;
	
	for (int i = 0; i < digitos; i++) {
		switch (vetor[i]) {
			case 0:
				for (int k = 0; k < linhas; k++) {
					if ((k == 0) || (k == (linhas - 1))) {
						for (int y = colunaAtual + 1; y < colunaAtual + s + 1; y++) {
							matriz[k][y] = "-";
						}
					} else {
						if (k != (linhas / 2)) {
							matriz[k][colunaAtual] = "|";
							matriz[k][colunaAtual + s + 1] = "|";
						}
					}
				}
				break;
				
			case 1:
				for (int k = 0; k < linhas; k++) {
					if ((k != 0) && (k != (linhas - 1)) && (k != (linhas /2))) {
						matriz[k][colunaAtual + s + 1] = "|";
					}
				}
				break;
				
			case 2:
				for (int k = 0; k < linhas; k++) {
						if ((k == 0) || (k == (linhas - 1)) || (k == (linhas / 2))) {
							for (int y = colunaAtual + 1; y < colunaAtual + s + 1; y++) {
								matriz[k][y] = "-";
							}
						} else {
							if (k < (linhas /2)) {
								matriz[k][colunaAtual + s + 1] = "|";
							} else {
								matriz[k][colunaAtual] = "|";
							}
						}
					}
				break;
				
			case 3:
				for (int k = 0; k < linhas; k++) {
						if ((k == 0) || (k == (linhas - 1)) || (k == (linhas / 2))) {
							for (int y = colunaAtual + 1; y < colunaAtual + s + 1; y++) {
								matriz[k][y] = "-";
							}
						} else {
							matriz[k][colunaAtual + s + 1] = "|";
						}
					}
				break;
				
			case 4:
				for (int k = 0; k < linhas; k++) {
						if (k == (linhas / 2)) {
							for (int y = colunaAtual + 1; y < colunaAtual + s + 1; y++) {
								matriz[k][y] = "-";
							}
						} else {
							if ((k != 0) && (k != linhas - 1)) {
								if (k < (linhas /2)) {
									matriz[k][colunaAtual] = "|";
									matriz[k][colunaAtual + s + 1] = "|";
								} else {
									matriz[k][colunaAtual + s + 1] = "|";
								}
							}
						}
					}
				break;
				
			case 5:
				for (int k = 0; k < linhas; k++) {
						if ((k == 0) || (k == (linhas - 1)) || (k == (linhas / 2))) {
							for (int y = colunaAtual + 1; y < colunaAtual + s + 1; y++) {
								matriz[k][y] = "-";
							}
						} else {
							if (k < (linhas /2)) {
								matriz[k][colunaAtual] = "|";
							} else {
								matriz[k][colunaAtual + s + 1] = "|";
							}
						}
					}
				break;
				
			case 6:
				for (int k = 0; k < linhas; k++) {
						if ((k == 0) || (k == (linhas - 1)) || (k == (linhas / 2))) {
							for (int y = colunaAtual + 1; y < colunaAtual + s + 1; y++) {
								matriz[k][y] = "-";
							}
						} else {
							if (k < (linhas /2)) {
								matriz[k][colunaAtual] = "|";
							} else {
								matriz[k][colunaAtual] = "|";
								matriz[k][colunaAtual + s + 1] = "|";
							}
						}
					}
				break;
				
			case 7:
				for (int k = 0; k < linhas; k++) {
					if (k == 0) {
						for (int y = colunaAtual + 1; y < colunaAtual + s + 1; y++) {
							matriz[k][y] = "-";
						}
					} else {
						if ((k != (linhas / 2)) && (k != linhas - 1)) {
							matriz[k][colunaAtual + s + 1] = "|";
						}
					}
				}
				break;
				
			case 8:
				for (int k = 0; k < linhas; k++) {
					if ((k == 0) || (k == (linhas - 1)) || (k == (linhas / 2))) {
						for (int y = colunaAtual + 1; y < colunaAtual + s + 1; y++) {
							matriz[k][y] = "-";
						}
					} else {
						matriz[k][colunaAtual] = "|";
						matriz[k][colunaAtual + s + 1] = "|";
					}
				}
				break;
				
			case 9:
				for (int k = 0; k < linhas; k++) {
						if ((k == 0) || (k == (linhas - 1)) || (k == (linhas / 2))) {
							for (int y = colunaAtual + 1; y < colunaAtual + s + 1; y++) {
								matriz[k][y] = "-";
							}
						} else {
							if (k < (linhas /2)) {
								matriz[k][colunaAtual] = "|";
								matriz[k][colunaAtual + s + 1] = "|";
							} else {
								matriz[k][colunaAtual + s + 1] = "|";
							}
						}
					}
				break;
				
		}
		colunaAtual += s + 3;
	}
	
	for (int i = 0; i < linhas; i++) {
		for (int j = 0; j < colunas; j++) {
			cout << matriz[i][j];
		}
		cout << endl;
	}
	cout << endl;
}

int main (int argc, char const* argv[]) {
	int s;
	int digitos;
	cin >> s;
	int sai = 1;
	
	while ((s != 0) && (sai != 0)) {
		sai = 0;
		string numberString;
		getline(cin, numberString);
		digitos = 0;
		
		int vetorTemp[20];
		sai = 0;
		
		int j = 0;
		for (int i = 0; i < numberString.length(); i++) {
			char c = numberString[i];
			switch (c) {
					case ' ': break;
					case '0': vetorTemp[j] = 0; digitos++; j++; break;
					case '1': vetorTemp[j] = 1; digitos++; sai = 1; j++; break;
					case '2': vetorTemp[j] = 2; digitos++; sai = 1; j++; break;
					case '3': vetorTemp[j] = 3; digitos++; sai = 1; j++; break;
					case '4': vetorTemp[j] = 4; digitos++; sai = 1; j++; break;
					case '5': vetorTemp[j] = 5; digitos++; sai = 1; j++; break;
					case '6': vetorTemp[j] = 6; digitos++; sai = 1; j++; break;
					case '7': vetorTemp[j] = 7; digitos++; sai = 1; j++; break;
					case '8': vetorTemp[j] = 8; digitos++; sai = 1; j++; break;
					case '9': vetorTemp[j] = 9; digitos++; sai = 1; j++; break;
			}
		}
		
		if (sai == 0) break;
		
		int vetor[digitos];
		
		for (int i = 0; i < digitos; i++) {
			vetor[i] = vetorTemp[i];
		}
		
		desenha(s, digitos, vetor);
		cin >> s;
		sai = 1;
	}
	return 0;
}

paaulocezar
New poster
Posts: 5
Joined: Thu May 14, 2009 4:14 pm

Re: 706 - LC-Display

Post by paaulocezar » Thu May 14, 2009 4:20 pm

well, I think it's allright with my code.
tried all I could but still get WA.
some tips ?

Code: Select all

REMOVED AFTER AC.
Last edited by paaulocezar on Tue May 26, 2009 8:51 pm, edited 1 time in total.

AltCtrlDel
New poster
Posts: 3
Joined: Sun Jun 04, 2006 1:08 pm

Re: 706 - LC-Display

Post by AltCtrlDel » Mon May 18, 2009 5:45 am

So basic .. still a run-time error!

Could anybody please help?!

Code: Select all

Code Removed After AC
Last edited by AltCtrlDel on Tue May 26, 2009 10:48 pm, edited 1 time in total.

paaulocezar
New poster
Posts: 5
Joined: Thu May 14, 2009 4:14 pm

Re: 706 - LC-Display

Post by paaulocezar » Tue May 26, 2009 9:02 pm

A tip is look the way data input is made.
blank lines between the test cases can generate a WA.

panda_coder
New poster
Posts: 7
Joined: Mon Jun 08, 2009 4:02 am

Re: 706 - LC-Display

Post by panda_coder » Mon Jun 15, 2009 4:43 am

Code: Select all

import java.io.*;
import java.util.*;

public class Main implements Runnable {
	static String readLine(int maxLength) {
		byte line[] = new byte[maxLength];
		int length = 0;
		int input = -1;
		try {
			while(length < maxLength) {
				input = System.in.read();
				if((input < 0) || (input == '\n')) break;
				line[length++] += input;
			}
			if((input<0) && (length ==0)) return null;
			return new String(line, 0, length);
		}catch(IOException e) {
			return null;
		}
	}
	
	public static void main(String[] args) {
		Main lcd = new Main();
		lcd.run();
	}
	public void run() {
		new myProgram().run();
	}
	
class myProgram implements Runnable {
	public void run() {
		int[][] display = new int[10][7];
		final String blank = " ";
		display[0] = new int[] {1,1,1,0,1,1,1};
		display[1] = new int[] {0,0,1,0,0,1,0};
		display[2] = new int[] {1,0,1,1,1,0,1};
		display[3] = new int[] {1,0,1,1,0,1,1};
		display[4] = new int[] {0,1,1,1,0,1,0};
		display[5] = new int[] {1,1,0,1,0,1,1};
		display[6] = new int[] {1,1,0,1,1,1,1};
		display[7] = new int[] {1,0,1,0,0,1,0};
		display[8] = new int[] {1,1,1,1,1,1,1};
		display[9] = new int[] {1,1,1,1,0,1,1};
	
		String line;
		while((line = readLine(512))!=null) {
			StringTokenizer st = new StringTokenizer(line);
			int size = Integer.parseInt(st.nextToken());
			String number = st.nextToken();
			if(size == 0 && number.equals("0")) break;
			int length = number.length();
			for(int i=0; i<7; i++) {
					if(i%3 == 0){ /// horizontal line
						for(int j=0;j<length;j++) {
							int sign = display[(int)number.charAt(j)-48][i];
							System.out.print(blank);
							for(int k=0;k<size;k++) {
								if(sign == 1) System.out.print("-");
								else System.out.print(blank);
							}
							System.out.print(blank);
							System.out.print(blank);   // ?
						}
						
					}
					else { 
						for(int k=0;k<size;k++) {
							for(int j=0;j<length;j++) {
								int sign = display[(int)number.charAt(j)-48][i];
								if(sign == 1) System.out.print("|");
								else System.out.print(" ");
								sign = display[(int)number.charAt(j)-48][i+1];
								for(int m=0;m<size;m++) {
									System.out.print(blank);  }
								if(sign == 1) System.out.print("|");
								else System.out.print(" ");
								if(j!=length-1) System.out.print(blank); // digit ??
							}
						   if(k!=size-1) System.out.println();
						}
					i+=1;	
					}
				if(i!=6) System.out.println();
			}
			}
	}
	}
}


My program has time-limited error in uva online judge, and presentation error in programming challenges.

I double checked that it fills all the white space occupied by the digits, and added a blank column between digits, but I don't know why presentation error,

and even worse -- time-limted error in uva. :(

Does anyone have any good idea to improve/get it accepted, please? =(

jimms
New poster
Posts: 1
Joined: Sat Aug 08, 2009 6:07 am

706 - LCD Display

Post by jimms » Sat Aug 08, 2009 6:23 am

I got a "Runtime error"
But I can't find bug, can someone tell me?
thanks.

**CODE DELETED **

I have found out why alway got "RE".

because I use "main()" not "int main(int argc, char *argv[])" lol :oops:

ZekeDragon
New poster
Posts: 1
Joined: Sun Sep 06, 2009 9:48 am

Re: 706 - LC-Display

Post by ZekeDragon » Sun Sep 06, 2009 9:55 am

I don't know how active these boards are, but either way...

Well I give up. I've tried submitting three consecutively easier to figure out versions of this program and time and again your computer gives me "Wrong Answer" as a result. Have no idea why, but hey, maybe someone here can figure that out?

My code is below, should be easy to copy/paste it into a file and build with g++. Here yah go:

Code: Select all

#include <exception>
#include <stdexcept>
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <memory>
#include <utility>
#include <fstream>

#define LCN_TOP 0
#define LCN_UP_LEFT 1
#define LCN_UP_RIGHT 2
#define LCN_MID 3
#define LCN_LOW_LEFT 4
#define LCN_LOW_RIGHT 5
#define LCN_BOTTOM 6

/* Everything here's function should be relatively obvious. I hope
   there's no need to explain this stuff...                          */

class DigException : public std::exception
{
    virtual const char* what() const throw()
    {
        return "DigException";
    }
};

class Digit
{
    bool locations[7];
    /* 0 - TOP
       1 - UPPER LEFT
       2 - UPPER RIGHT
       3 - MIDDLE
       4 - LOWER LEFT
       5 - LOWER RIGHT
       6 - BOTTOM       */

public:
    Digit (const bool top, const bool ul, const bool ur,
            const bool mid, const bool ll, const bool lr, const bool bot) throw()
    {
        locations[0] = top;
        locations[1] = ul;
        locations[2] = ur;
        locations[3] = mid;
        locations[4] = ll;
        locations[5] = lr;
        locations[6] = bot;
    }

    bool isSectionOn(const int sec) const throw()
    {
        if (sec < 0 || sec > 6)
        {
            std::cout << "Bad Request made to isSectionOn\nPlease Debug Application." << std::endl;
            return false;
        }
        else return locations[sec];
    }
};

class One : public Digit
{
public:
    One () : Digit(false, false, true, false, false, true, false)
    {
    }
};

class Two : public Digit
{
public:
    Two () : Digit(true, false, true, true, true, false, true)
    {
    }
};

class Three : public Digit
{
public:
    Three () : Digit(true, false, true, true, false, true, true)
    {
    }
};

class Four : public Digit
{
public:
    Four () : Digit(false, true, true, true, false, true, false)
    {
    }
};

class Five : public Digit
{
public:
    Five () : Digit(true, true, false, true, false, true, true)
    {
    }
};

class Six : public Digit
{
public:
    Six () : Digit(true, true, false, true, true, true, true)
    {
    }
};

class Seven : public Digit
{
public:
    Seven () : Digit(true, false, true, false, false, true, false)
    {
    }
};

class Eight : public Digit
{
public:
    Eight () : Digit(true, true, true, true, true, true, true)
    {
    }
};

class Nine : public Digit
{
public:
    Nine () : Digit(true, true, true, true, false, true, true)
    {
    }
};

class Zero : public Digit
{
public:
    Zero () : Digit(true, true, true, false, true, true, true)
    {
    }
};

class NumberFactory
{
public:
    Digit* makeDigit(int dig) throw(std::bad_alloc)
    {
        switch (dig)
        {
            case 0:
                return new Zero();

            case 1:
                return new One();

            case 2:
                return new Two();

            case 3:
                return new Three();

            case 4:
                return new Four();

            case 5:
                return new Five();

            case 6:
                return new Six();

            case 7:
                return new Seven();

            case 8:
                return new Eight();

            case 9:
                return new Nine();

            default:
                return NULL;
        }
    }
};

class Parser
{
    std::string tempstring;

///////////////////////////////////////////////////////////////////////////////
//
// This function parses each vertical facing row, making sure that all the
// line breaks are parsed properly and there are sufficient rows. This does the
// "|" characters, as opposed to the "-" characters.
//
//=============================================================================
void verticalParser(bool* barray, int arraySize, int digitSize) throw(std::bad_alloc)
//=============================================================================
{
  try
  {
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    for (int iii = 0; iii < digitSize; ++iii)
    {
        for (int jjj = 0; jjj < arraySize; ++jjj)
        {
            if (barray[jjj] == true)
            {
                tempstring.append("|");
            }
            else
            {
                tempstring.append(" ");
            }

            if (jjj % 2 == 0)
            {
                tempstring.append(digitSize, ' ');
            }
            else
            {
                if (jjj != arraySize - 1)
                {
                    tempstring.append(" ");
                }
            }
        }
        tempstring.append("\n");
    }

//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  }
  catch (std::bad_alloc&)
  {
    std::cout << "Sent by horizontalParser..." << std::endl;
    throw;
  }
}

///////////////////////////////////////////////////////////////////////////////
//
// This function parses each horizontally facing row in the LCD Numbers (all the
// rows made up of "-" characters, rather than "|" characters).
//
//=============================================================================
void horizontalParser(bool* barray, int arraySize, int digitSize) throw(std::bad_alloc)
//=============================================================================
{
  try
  {
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    tempstring.append(" ");
    for (int iii = 0; iii < arraySize; ++iii)
    {
        if (barray[iii] == true)
        {
            tempstring.append(digitSize, '-');
        }
        else
        {
            tempstring.append(digitSize, ' ');
        }
        if (iii != arraySize - 1)
        {
            tempstring.append("   ");
        }
    }
    tempstring.append("\n");

//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  }
  catch (std::bad_alloc&)
  {
    std::cout << "Sent by verticalParser..." << std::endl;
    throw;
  }
}

///////////////////////////////////////////////////////////////////////////////
//
// This function just deletes the allocated memory from the Digit*s so that
// the auto_ptr vector can die in peace.
//
//=============================================================================
void clearVector(std::auto_ptr< std::vector< Digit* > > clrVec) throw(std::out_of_range)
//=============================================================================
{
    for (int iii = clrVec->size() - 1; iii >= 0; --iii)
    {
        delete clrVec->at(iii);
    }
}

public:

///////////////////////////////////////////////////////////////////////////////
//
// This function is the main organizer of the application. It takes on the
// responsibility of creating each string. It will only parse one command
// pair at a time.
//
//=============================================================================
std::auto_ptr< std::string > parse(std::auto_ptr< std::vector< Digit* > > mainVec, int size) throw()
//=============================================================================
{
  try
  {
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    std::auto_ptr< std::string > totalstring(new std::string);
    bool* barray = new bool[mainVec->size() * 2];
    for (int iii = 0; iii < 3; ++iii)
    {

//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
      try
      {
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

        for (unsigned int jjj = 0; jjj < mainVec->size(); ++jjj)
        {
            if (iii == 0)
            {
                barray[jjj] = (mainVec->at(jjj))->isSectionOn(LCN_TOP);
            }
            else if (iii == 1)
            {
                barray[jjj] = (mainVec->at(jjj))->isSectionOn(LCN_MID);
            }
            else
            {
                barray[jjj] = (mainVec->at(jjj))->isSectionOn(LCN_BOTTOM);
            }
        }

//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
      }
      catch (std::out_of_range&)
      {
          std::cout << "mainVec called out_of_range on first for loop in Parser::parse" << std::endl;
          throw;
      }
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

        horizontalParser(barray, mainVec->size(), size);
        totalstring->append(tempstring);
        tempstring.clear();

        if (iii < 2)
        {

//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
          try
          {
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

            for (unsigned int jjj = 0; jjj < mainVec->size(); ++jjj)
            {

                /* I chose to use "jjj * 2" followed by "(jjj * 2) + 1" because of where
                   jjj starts, and the nature of the array I was using. I would need every
                   even number to be the left side of the Digit we were printing, and every
                   odd number to be the right side of the Digit. In order to do this, I had
                   to employ some funky mathematics. EXAMPLE: if jjj = 3: 3 * 2 = 6, so
                   location 6 would be LCN_XXX_LEFT and location 7 would be LCN_XXX_RIGHT,
                   then on the following iteration jjj would equal 4, and thus 4 * 2 = 8,
                   and so LCN_XXX_LEFT is 8 and LCN_XXX_RIGHT is 9, etc.                     */

                if (iii == 0)
                {
                    barray[jjj * 2] = (mainVec->at(jjj))->isSectionOn(LCN_UP_LEFT);
                    barray[(jjj * 2) + 1] = (mainVec->at(jjj))->isSectionOn(LCN_UP_RIGHT);
                }
                else
                {
                    barray[jjj * 2] = (mainVec->at(jjj))->isSectionOn(LCN_LOW_LEFT);
                    barray[(jjj * 2) + 1] = (mainVec->at(jjj))->isSectionOn(LCN_LOW_RIGHT);
                }
            }

//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
          }
          catch (std::out_of_range&)
          {
              std::cout << "mainVec called out_of_range on second for loop in Parser::parse" << std::endl;
              throw;
          }
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

        verticalParser(barray, mainVec->size() * 2, size);
        totalstring->append(tempstring);
        tempstring.clear();

        }

    }

    delete[] barray;
    clearVector(mainVec);
    return totalstring;

//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  }
  catch (std::exception& e)
  {
    std::cout << "Caught exception in parse function: " << e.what() << std::endl;
    exit(EXIT_FAILURE);
  }
}
};

class Starter
{
protected:
    std::vector< int > numberSet;
    NumberFactory numFact;
    Parser prs;
    int size;
    std::string progName;

void failInput() throw()
{
    std::cout << "Please use proper command-line input.\nExample: " << progName << " 3 142\n"
                 "Produces three numbers size 3." << std::endl;
}

void setProgName(const char* fiName)
{
    int lastSlash = 0;
    for (int iii = 0; fiName[iii] != '\0'; ++iii)
    {
        if (fiName[iii] == '\\' || fiName[iii] == '/')
        {
            lastSlash = iii + 1;
        }
    }
    progName.assign(&fiName[lastSlash]);
}

bool checkUserInput(const char* arg1, const char* arg2)
{
    if (*arg1 == '0' && *arg2 == '0')
        return true;

    if (atoi(arg1) == 0 || (atoi(arg2) == 0 && *arg2 != '0'))
    {
        failInput();
        return false;
    }

    if (atoi(arg1) < 1 || atoi(arg1) > 9)
    {
        std::cout << "Please use a size from 1 to 9, no other sizes are permitted.\n"
                     "Example: " << progName << " 3 142\n"
                     "Produces three numbers size 3." << std::endl;
        return false;
    }

    return true;
}

    int getLength(char* arg) throw()
    {
        int retval = 0;
        for (int iii = 0; arg[iii] != '\0'; ++iii)
        {
            ++retval;
        }
        return retval;
    }

public:

Starter(int argc, char** argv) throw()
{
    setProgName(argv[0]);
    if (argc == 3 && checkUserInput(argv[1], argv[2]))
    {
    }
    else
    {
        exit(EXIT_SUCCESS);
    }

    size = atoi(argv[1]);
    int anum = getLength(argv[2]);

//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  try
  {
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    for (int iii = 0; iii < anum; ++iii)
    {
        char* temp = new char(argv[2][iii]);
        numberSet.push_back(atoi( (const char*) temp) );
        delete temp;
    }

//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  }
  catch (std::bad_alloc&)
  {
    std::cout << "Exception thrown by Starter::Starter: bad_alloc" << std::endl;
    exit(EXIT_FAILURE);
  }
}

    Starter() throw() {};
    virtual ~Starter() throw() {};

char analyzeNumber(int anum)
{
    if (anum < 0)
    {
        return 'n';
    }
    else if (anum > 9)
    {
        return 'l';
    }
    else
    {
        return 'p';
    }
}

virtual void run() throw(std::bad_alloc)
{
    std::auto_ptr< std::vector< Digit* > > digVect(new std::vector< Digit* >);
    bool retry = false;
    for (unsigned int iii = 0; iii < numberSet.size(); ++iii)
    {
        if (retry) --iii;
        Digit* temp = numFact.makeDigit(numberSet.at(iii));
        if (temp == NULL)
        {
            if (analyzeNumber(numberSet.at(iii)) == 'l')
            {
                // This shouldn't have happened, but something's going on to my input.
                if (numberSet.at(iii + 1) == numberSet.at(iii) % 10)
                {
                    numberSet.at(iii) = numberSet.at(iii) / 10;
                }
                else
                {
                    std::vector<int>::iterator it = numberSet.begin() + iii;
                    numberSet.insert(it, numberSet.at(iii) % 10);
                    numberSet.at(iii) = numberSet.at(iii) / 10;
                }
            }
            else if (analyzeNumber(numberSet.at(iii)) == 'n')
            {
                // Why the **** is it negative?
                numberSet.at(iii) = abs(numberSet.at(iii));
            }
            retry = true;
            continue;
        }
        digVect->push_back(numFact.makeDigit(numberSet.at(iii)));
    }
    std::auto_ptr< std::string > theString = prs.parse(digVect, size);
    std::cout << *theString << std::endl;
}
};

class ComplexStarter : public Starter
{
    bool fromFile;
    std::streambuf *blackup;
    std::ifstream *froFile;
    std::vector< std::pair< char*, char* >* > commandSet;

void getUserInput()
{
    std::string input;
    char* test1, *test2;
    while (true)
    {
        getline(std::cin, input);
        if (input.at(1) != ' ')
        {
            failInput();
            std::cout << "Or input '0 0' to print and exit." << std::endl;
            continue;
        }

        test1 = new char(input.at(0));
        test2 = new char[input.size() - 2];

        for (unsigned int iii = 2; iii < input.size(); ++iii)
        {
            test2[iii - 2] = input.at(iii);
        }

        if (checkUserInput(test1, test2))
        {
            if (*test1 == '0' && *test2 == '0' && test2[1] == '\0')
            {
                delete test1;
                delete[] test2;
                break;
            }
            else
            {
                commandSet.push_back(new std::pair< char*, char* > (test1, test2));
            }
        }
        else
        {
            failInput();
            std::cout << "Or input '0 0' to print and exit." << std::endl;
            delete test1;
            delete[] test2;
            test1 = NULL;
            test2 = NULL;
            continue;
        }
    }
}


public:

ComplexStarter(const char* prNm) : Starter(), fromFile(false)
{
    setProgName(prNm);

//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  try
  {
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    getUserInput();

//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  }
  catch (std::exception& e)
  {
      std::cout << "Error occured during user input: " << e.what() << std::endl;
      exit(EXIT_FAILURE);
  }
}

ComplexStarter(const char* prNm, const char* fileLoad) : Starter(), fromFile(false)
{
    setProgName(prNm);
    froFile = new std::ifstream(fileLoad, std::ifstream::in);
    if (*froFile != NULL)
    {
        fromFile = true;
        blackup = std::cin.rdbuf();
        std::cin.rdbuf(froFile->rdbuf());
        getUserInput();
    }
    else
    {
        std::cout << "File not found or is corrupt." << std::endl;
        exit(EXIT_SUCCESS);
    }
}

~ComplexStarter() throw()
{
    for (unsigned int iii = 0; iii < commandSet.size(); ++iii)
    {
        delete commandSet.at(iii)->first;
        delete[] commandSet.at(iii)->second;
        delete commandSet.at(iii);
    }
    if (fromFile)
    {
        froFile->close();
        delete froFile;
        std::cin.rdbuf(blackup);
    }
}

void run() throw(std::bad_alloc)
{
    int len = 0;
    for (unsigned int iii = 0; iii < commandSet.size(); ++iii)
    {
        numberSet.clear();
        len = getLength(commandSet.at(iii)->second);
        for (int jjj = 0; jjj < len; ++jjj)
        {
            char* temp = new char(commandSet.at(iii)->second[jjj]);
            numberSet.push_back(atoi( (const char*) temp) );
            delete temp;
        }
        size = atoi(commandSet.at(iii)->first);
        Starter::run();
    }
}
};

int main(int argc, char* argv[])
{
    Starter* start;
    if (argc == 1)
    {
        start = new ComplexStarter(argv[0]);
    }
    else if (argc == 2)
    {
        start = new ComplexStarter(argv[0], argv[1]);
    }
    else
    {
        start = new Starter(argc, argv);
    }
    start->run();
    delete start;
    return 0;
}
I wish this submitter worked, I'd have fun with this stuff...

behnam.hamidi
New poster
Posts: 2
Joined: Sat Feb 06, 2010 6:53 pm

Re: 706 - LC-Display

Post by behnam.hamidi » Sat Feb 06, 2010 7:46 pm

hello
i get a WA again and again plz help me i dont know why?
this is my code
plz mail my mistake to=behnam.hamidi1369@gmail.com
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
int num,size,i,j,k,num1=0,b,l,s;
char a[100];
//int a[1000];
//int a[1000];
while(cin>>size>>a){
if(size == 0 && strchr(a,'0') != NULL)
return 0;
k=strlen(a);
// cout<<strlen(v);
//system("pause");
for(i=0;a;i++)a-=48;
// for(i=0;a;i++)printf("%d",a);
/* for(;num>0;)
{
num1 = num1*10+num%10 ;
num/=10;
}*/
// cout<<num1;
//for(i=0;c;i++)a=c-48;

//for(i=0;i<k;i++)cout<<a;
//for(i=0;i<k;i++)cout<<a;
int line=1;
if(line==1){
for(i=0;i<k;i++){
if(a!=1&&a[i]!=4)
{
cout<<' ';
for(j=0;j<size;j++)
{
cout<<'-';
}
cout<<' ';
if(i!=k-1)
cout<<' ';
}
if((a[i]==1||a[i]==4))
{
cout<<' ';
for(j=0;j<size;j++)
{
cout<<' ';
}
cout<<' ';
if(i!=k-1)
cout<<' ';
}


}
}
line++;
cout<<endl;
//cout<<" ";
//=======================================
for(s=0;s<size;s++){
if(line==2)
{
for(i=0;i<k;i++){
if((a[i]==7||a[i]==2||a[i]==3||a[i]==1))
{
cout<<' ';
for(j=0;j<size;j++)
{
cout<<' ';
}
cout<<'|';
if(i!=k-1)
cout<<' ';
}

if((a[i]==5||a[i]==6))
{
cout<<'|';
for(j=0;j<size;j++)
{
cout<<' ';
}
cout<<' ';
if(i!=k-1)
cout<<' ';
}
if(a[i]==4||a[i]==8||a[i]==9||a[i]==0)
{
cout<<'|';
for(j=0;j<size;j++)
{
cout<<' ';
}
cout<<'|';
if(i!=k-1)
cout<<' ';

}


}

}
cout<<endl;
}
//cout<<" ";
line++;
//cout<<endl;
if(line==3)
{
for(i=0;i<k;i++)
{
if(a[i]!=1&&a[i]!=7&&a[i]!=0)
{
cout<<' ';
for(j=0;j<size;j++)
{
cout<<'-';
}
cout<<' ';
if(i!=k-1)
cout<<' ';
}

if(a[i]==1||a[i]==7||a[i]==0){
cout<<' ';
for(j=0;j<size;j++)
{
cout<<' ';
}
cout<<' ';
if(i!=k-1)
cout<<' ';
}
}

}
cout<<endl;
line++;
//cout<<" ";
//=======================================
for(s=0;s<size;s++){
if(line==4)
{
for(i=0;i<k;i++){
if((a[i]==5||a[i]==4||a[i]==3||a[i]==1||a[i]==7||a[i]==9))
{
cout<<' ';
for(j=0;j<size;j++)
{
cout<<' ';
}
cout<<'|';
if(i!=k-1)
cout<<' ';
}
if((a[i]==2))
{
cout<<'|';
for(j=0;j<size;j++)
{
cout<<' ';
}
cout<<' ';
if(i!=k-1)
cout<<' ';
}
if(a[i]==6||a[i]==8||a[i]==0)
{
cout<<'|';
for(j=0;j<size;j++)
{
cout<<' ';
}
cout<<'|';
if(i!=k-1)
cout<<' ';

}


}

}
cout<<endl;
}
line++;
//cout<<" ";
if(line==5){
for(i=0;i<k;i++){
if(a[i]!=1&&a[i]!=4&&a[i]!=7)
{
cout<<' ';
for(j=0;j<size;j++)
{
cout<<'-';
}
cout<<' ';
if(i!=k-1)
cout<<' ';
}
if(a[i]==1||a[i]==4||a[i]==7)
{
cout<<' ';
for(j=0;j<size;j++)
{
cout<<' ';
}
cout<<' ';
if(i!=k-1)
cout<<' ';
}


}}
cout<<endl;
}
}
plz help me :oops: :oops:

tristanx9
New poster
Posts: 4
Joined: Mon Mar 08, 2010 11:35 pm

Re: 706 - LC-Display

Post by tristanx9 » Tue Apr 13, 2010 10:07 pm

Hi everybody! I did everything right (or apparently not :( ) I have tested with all cases I found and it was all just fine. I checked the spaces between the numbers and the space in the end. I replace the spaces by "." for check. the code, input and output is here. Can someone please help?

Code:

Code: Select all

/*
 * The idea is that the numbers are divided in 5 parts
 * 1 - first horizontal line
 * 2 - n vertical lines 
 * 3 - horizontal mid line 
 * 4 - n vertical lines
 * 5 - last horizontal line
 */

import java.io.*;

class Main{
    
    public int n;

    void imprime(String num){

        int comprimento = num.length();
        String linha = "";

        //part 1
        for(int i=0; i<comprimento; i++){

            linha += ".";
            switch(num.charAt(i)){
                case '1':
                case '4':
                    for(int j=0;j<n;j++) linha += ".";
                    break;
                case '0':
                case '2':
                case '3':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                    for(int j=0;j<n;j++) linha += "-";
            }
            linha += ".";
            if(i!=comprimento-1) linha += ".";
        }
        System.out.println(linha);
        linha = "";


        //part 2
        for(int i=0; i<comprimento; i++){

            switch(num.charAt(i)){
                case '1':
                case '2':
                case '3':
                case '7':
                    linha += ".";
                    for(int j=0;j<n;j++) linha += ".";
                    linha += "|";
                    if(i!=comprimento-1) linha += ".";
                    break;
                case '0':
                case '4':
                case '8':
                case '9':
                    linha += "|";
                    for(int j=0;j<n;j++) linha += ".";
                    linha += "|";
                    if(i!=comprimento-1) linha += ".";
                    break;
                case '6':
                case '5':
                     linha += "|";
                     for(int j=0;j<n;j++) linha += ".";
                     linha += ".";
                     if(i!=comprimento-1) linha += ".";
                     break;
            }
        }
        for(int j=0;j<n;j++) System.out.println(linha);
        linha = "";

        //part 3
        for(int i=0; i<comprimento; i++){

            linha += ".";
            switch(num.charAt(i)){
                case '1':
                case '0':
                case '7':
                    for(int j=0;j<n;j++) linha += ".";
                    break;
                case '4':
                case '2':
                case '3':
                case '5':
                case '6':
                case '8':
                case '9':
                    for(int j=0;j<n;j++) linha += "-";
            }
            linha += ".";
            if(i!=comprimento-1) linha += ".";
        }
        System.out.println(linha);
        linha = "";

        //part 4
        for(int i=0; i<comprimento; i++){

            switch(num.charAt(i)){
                case '1':
                case '4':
                case '3':
                case '7':
                case '5':
                case '9':
                    linha += ".";
                    for(int j=0;j<n;j++) linha += ".";
                    linha += "|";
                    if(i!=comprimento-1) linha += ".";
                    break;
                case '0':
                case '6':
                case '8':
                    linha += "|";
                    for(int j=0;j<n;j++) linha += ".";
                    linha += "|";
                    if(i!=comprimento-1) linha += ".";
                    break;
                case '2':
                     linha += "|";
                     for(int j=0;j<n;j++) linha += ".";
                     linha += ".";
                     if(i!=comprimento-1) linha += ".";
                     break;
            }
        }
        for(int j=0;j<n;j++) System.out.println(linha);
        linha = "";


        //part 5
        for(int i=0; i<comprimento; i++){

            linha += ".";
            switch(num.charAt(i)){
                case '1':
                case '4':
                case '7':
                    for(int j=0;j<n;j++) linha += ".";
                    break;
                case '0':
                case '2':
                case '3':
                case '5':
                case '6':
                case '8':
                case '9':
                    for(int j=0;j<n;j++) linha += "-";
            }
            linha += ".";
            if(i!=comprimento-1) linha += ".";
        }
        System.out.println(linha);
        linha = "";
           
    }

    void Begin() throws IOException {

        BufferedReader entrada;
        entrada = new BufferedReader (new InputStreamReader(System.in));
        String linha, numero;
        String [] token;
        int controle = 0;

        while(!(linha = entrada.readLine()).equals("0 0")){
            token = linha.split("\\s");

            if(controle == 0) controle = 1;
            else System.out.println();

            n =Integer.parseInt(token[0]);

            imprime(token[1]);

        }
    }

    public static void main(String arg []) throws IOException{

        Main programa = new Main();
        programa.Begin();

    }
}

input:

Code: Select all

2 12345
3 67890
1 45876
6 45
10 1346
8 888888
1 0
0 0
output:

Code: Select all

......--...--........--.
...|....|....|.|..|.|...
...|....|....|.|..|.|...
......--...--...--...--.
...|.|.......|....|....|
...|.|.......|....|....|
......--...--........--.

.---...---...---...---...---.
|.........|.|...|.|...|.|...|
|.........|.|...|.|...|.|...|
|.........|.|...|.|...|.|...|
.---.........---...---.......
|...|.....|.|...|.....|.|...|
|...|.....|.|...|.....|.|...|
|...|.....|.|...|.....|.|...|
.---.........---...---...---.

.....-...-...-...-.
|.|.|...|.|...|.|..
.-...-...-.......-.
..|...|.|.|...|.|.|
.....-...-.......-.

..........------.
|......|.|.......
|......|.|.......
|......|.|.......
|......|.|.......
|......|.|.......
|......|.|.......
.------...------.
.......|........|
.......|........|
.......|........|
.......|........|
.......|........|
.......|........|
..........------.

..............----------................----------.
...........|............|.|..........|.|...........
...........|............|.|..........|.|...........
...........|............|.|..........|.|...........
...........|............|.|..........|.|...........
...........|............|.|..........|.|...........
...........|............|.|..........|.|...........
...........|............|.|..........|.|...........
...........|............|.|..........|.|...........
...........|............|.|..........|.|...........
...........|............|.|..........|.|...........
..............----------...----------...----------.
...........|............|............|.|..........|
...........|............|............|.|..........|
...........|............|............|.|..........|
...........|............|............|.|..........|
...........|............|............|.|..........|
...........|............|............|.|..........|
...........|............|............|.|..........|
...........|............|............|.|..........|
...........|............|............|.|..........|
...........|............|............|.|..........|
..............----------................----------.

.--------...--------...--------...--------...--------...--------.
|........|.|........|.|........|.|........|.|........|.|........|
|........|.|........|.|........|.|........|.|........|.|........|
|........|.|........|.|........|.|........|.|........|.|........|
|........|.|........|.|........|.|........|.|........|.|........|
|........|.|........|.|........|.|........|.|........|.|........|
|........|.|........|.|........|.|........|.|........|.|........|
|........|.|........|.|........|.|........|.|........|.|........|
|........|.|........|.|........|.|........|.|........|.|........|
.--------...--------...--------...--------...--------...--------.
|........|.|........|.|........|.|........|.|........|.|........|
|........|.|........|.|........|.|........|.|........|.|........|
|........|.|........|.|........|.|........|.|........|.|........|
|........|.|........|.|........|.|........|.|........|.|........|
|........|.|........|.|........|.|........|.|........|.|........|
|........|.|........|.|........|.|........|.|........|.|........|
|........|.|........|.|........|.|........|.|........|.|........|
|........|.|........|.|........|.|........|.|........|.|........|
.--------...--------...--------...--------...--------...--------.

.-.
|.|
...
|.|
.-.

User avatar
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: 706 - LC-Display

Post by sohel » Wed Apr 14, 2010 10:32 am

You can use this site - http://uvatoolkit.com/problemssolve.php for testing IO.

mustak
New poster
Posts: 8
Joined: Sun Sep 06, 2009 5:11 pm
Contact:

Re: 706 - LC-Display(presentation error)

Post by mustak » Fri Apr 23, 2010 12:18 pm

Code: Select all

#include<iostream>
#include<cstring>

using namespace std;

int main()
{
 long s,i,j,k,l,f;
 f=0;
 char n[10];   
 freopen("out.txt","w",stdout);
 while(1)
 {   
  cin>>s;
  cin>>n;
  
  if(s==0&&n[0]=='0')
  break;
  
  k=strlen(n);
  for(i=1;i<=2*s+3;i++)
  {
   for(l=0;l<k;l++)
   {
   if(n[l]=='1')
   {                                            
   for(j=1;j<=s+2;j++)
   {
    if(j==s+2)
    {
      if((i!=1)&&(i!=2*s+3)&&(i!=s+2))        
      cout<<"|";
      else
      cout<<" ";         
    }
    else
    cout<<" ";                   
   }
   }
   else if(n[l]=='2')
   {
   for(j=1;j<=s+2;j++)
   {
     if((i==1)||(i==s+2)||(i==2*s+3))
     {
      if((j!=1)&&(j!=s+2))
      cout<<"-";
      else
      cout<<" ";                                
     }
     else
     {
      if((i!=1)&&(i<s+2)&&(j==s+2))
      cout<<"|";
      else if((i>s+2)&&(i!=2*s+3)&&(j==1))
      cout<<"|";
      else
      cout<<" ";    
     }                    
   }
  }
  else if(n[l]=='3')
  {
   for(j=1;j<=s+2;j++)
   {
     if((i==1)||(i==s+2)||(i==2*s+3))
     {
      if((j!=1)&&(j!=s+2))
      cout<<"-";
      else
      cout<<" ";                                
     }
     else
     {
      if((i!=1)&&(i<s+2)&&(j==s+2))
      cout<<"|";
      else if((i>s+2)&&(i!=2*s+3)&&(j==s+2))
      cout<<"|";
      else
      cout<<" ";    
     }                    
   }
  }
  else if(n[l]=='4')
  {
   for(j=1;j<=s+2;j++)
   {
     if(i==s+2)
     {
      if((j!=1)&&(j!=s+2))
      cout<<"-";
      else
      cout<<" ";                                
     }
     else
     {
      if((i!=1)&&(i<s+2)&&(j==s+2))
      cout<<"|";
      else if((i>s+2)&&(i!=2*s+3)&&(j==s+2))
      cout<<"|";
      else if((i!=1)&&(i<s+2)&&(j==1))
      cout<<"|";
      else
      cout<<" ";    
     }                    
   }
  }
  else if(n[l]=='5')
  {
   for(j=1;j<=s+2;j++)
   {
     if((i==1)||(i==s+2)||(i==2*s+3))
     {
      if((j!=1)&&(j!=s+2))
      cout<<"-";
      else
      cout<<" ";                                
     }
     else
     {
      if((i>s+2)&&(i!=2*s+3)&&(j==s+2))
      cout<<"|";
      else if((i!=1)&&(i<s+2)&&(j==1))
      cout<<"|";
      else
      cout<<" ";    
     }                    
   }
  }
  else if(n[l]=='6')
  {
   for(j=1;j<=s+2;j++)
   {
     if((i==1)||(i==s+2)||(i==2*s+3))
     {
      if((j!=1)&&(j!=s+2))
      cout<<"-";
      else
      cout<<" ";                                
     }
     else
     {
      if((i!=1)&&(i<s+2)&&(j==1))
      cout<<"|";
      else if((i>s+2)&&(i!=2*s+3)&&(j==1))
      cout<<"|";
      else if((i>s+2)&&(i!=2*s+3)&&(j==s+2))
      cout<<"|";
      else
      cout<<" ";    
     }                    
   }
  }
  else if(n[l]=='7')
  {
   for(j=1;j<=s+2;j++)
   {
     if(i==1)
     {
      if((j!=1)&&(j!=s+2))
      cout<<"-";
      else
      cout<<" ";                                
     }
     else
     {
      if((i!=1)&&(i<s+2)&&(j==s+2))
      cout<<"|";
      else if((i>s+2)&&(i!=2*s+3)&&(j==s+2))
      cout<<"|";
      else
      cout<<" ";    
     }                    
   }
  }
  else if(n[l]=='8')
  {
   for(j=1;j<=s+2;j++)
   {
     if((i==1)||(i==s+2)||(i==2*s+3))
     {
      if((j!=1)&&(j!=s+2))
      cout<<"-";
      else
      cout<<" ";                                
     }
     else
     {
      if((i!=1)&&(i<s+2)&&(j==s+2))
      cout<<"|";
      else if((i>s+2)&&(i!=2*s+3)&&(j==1))
      cout<<"|";
      else if((i!=1)&&(i<s+2)&&(j==1))
      cout<<"|";
      else if((i>s+2)&&(i!=2*s+3)&&(j==s+2))
      cout<<"|";
      else
      cout<<" ";    
     }                    
   }
  }
  else if(n[l]=='9')
  {
   for(j=1;j<=s+2;j++)
   {
     if((i==1)||(i==s+2)||(i==2*s+3))
     {
      if((j!=1)&&(j!=s+2))
      cout<<"-";
      else
      cout<<" ";                                
     }
     else
     {
      if((i!=1)&&(i<s+2)&&(j==s+2))
      cout<<"|";
      else if((i!=1)&&(i<s+2)&&(j==1))
      cout<<"|";
      else if((i>s+2)&&(i!=2*s+3)&&(j==s+2))
      cout<<"|";
      else
      cout<<" ";    
     }                    
   }
  }
  else if(n[l]=='0')
  {
   for(j=1;j<=s+2;j++)
   {
     if((i==1)||(i==2*s+3))
     {
      if((j!=1)&&(j!=s+2))
      cout<<"-";
      else
      cout<<" ";                                
     }
     else
     {
      if((i!=1)&&(i<s+2)&&(j==s+2))
      cout<<"|";
      else if((i>s+2)&&(i!=2*s+3)&&(j==1))
      cout<<"|";
      else if((i!=1)&&(i<s+2)&&(j==1))
      cout<<"|";
      else if((i>s+2)&&(i!=2*s+3)&&(j==s+2))
      cout<<"|";
      else
      cout<<" ";    
     }                    
   }
   }
   if(l!=k-1)
   cout<<" ";
  }
   
   cout<<endl;                   
  }   
  cout<<endl;
 }  
 return 0;    
}
I got presentation error on that problem. Please help me.

phars_alnmr
New poster
Posts: 2
Joined: Wed Aug 18, 2010 2:03 am

Re: 706 - LC-Display

Post by phars_alnmr » Wed Aug 18, 2010 2:08 am

I always get WA in PC & runtimr error in UVA
plz help this is my code

Code: Select all

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;


public class LCDDisplay {
    public static int LCD[][];
     public static void main (String args[])throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        //new InputStreamReader(System.in)
        String s=in.readLine();
        while(!s.equals("0 0")){
            int n=Integer.parseInt(s.substring(0, s.indexOf(" ")));
            String num=s.substring(s.indexOf(" ")+1);
            num=Integer.parseInt(num)+"";
            int col=((n+3)*num.length())-1;
            int row=2*n+3;
            LCD=new int[row][col];
            for(int i=0;i<num.length();i++){
                draw(num.charAt(i),i,n);
            }
            print();
            s=in.readLine();
            if(!s.equals("0 0"))System.out.println();
        }
        System.out.close();
        System.exit(0);
    }

    public static void draw(char num, int order, int n) {
        int row=2*n+3;
        int col=n+2;
        int offset=order*(n+3);
        if(num=='0'){
            for(int i=offset+1;i<col+offset-1;i++){
                LCD[0][i]=2;
                LCD[row-1][i]=2;
            }
            for(int i=1;i<row-1;i++){
                if(i==(row)/2)continue;
                LCD[i][offset]=1;
                LCD[i][offset+col-1]=1;
            }
        }
        else if(num=='1'){
            for(int i=1;i<row-1;i++){
                if(i==(row)/2)continue;
                LCD[i][offset+col-1]=1;
            }
        }
        else if(num=='2'){
            for(int i=offset+1;i<col+offset-1;i++){
                LCD[0][i]=2;
                LCD[row-1][i]=2;
                LCD[(row-1)/2][i]=2;
            }
            for(int i=1;i<row-1;i++){
                if(i==(row)/2)continue;
                else if(i>(row)/2)LCD[i][offset]=1;
                else LCD[i][offset+col-1]=1;
            }
        }
        else if(num=='3'){
            for(int i=offset+1;i<col+offset-1;i++){
                LCD[0][i]=2;
                LCD[row-1][i]=2;
                LCD[(row-1)/2][i]=2;
            }
            for(int i=1;i<row-1;i++){
                if(i==(row)/2)continue;
                LCD[i][offset+col-1]=1;
            }
        }
        else if(num=='4'){
            for(int i=offset+1;i<col+offset-1;i++){
                LCD[(row-1)/2][i]=2;
            }
            for(int i=1;i<row-1;i++){
                if(i==(row)/2)continue;
                else if(i<(row)/2)LCD[i][offset]=1;
                LCD[i][offset+col-1]=1;
            }
        }
        else if(num=='5'){
            for(int i=offset+1;i<col+offset-1;i++){
                LCD[0][i]=2;
                LCD[row-1][i]=2;
                LCD[(row-1)/2][i]=2;
            }
            for(int i=1;i<row-1;i++){
                if(i==(row)/2)continue;
                else if(i<(row)/2)LCD[i][offset]=1;
                else LCD[i][offset+col-1]=1;
            }
        }
        else if(num=='6'){
            for(int i=offset+1;i<col+offset-1;i++){
                LCD[0][i]=2;
                LCD[row-1][i]=2;
                LCD[(row-1)/2][i]=2;
            }
            for(int i=1;i<row-1;i++){
                if(i==(row)/2)continue;
                LCD[i][offset]=1;
                if(i>row/2)LCD[i][offset+col-1]=1;
            }
        }
        else if(num=='7'){
            for(int i=offset+1;i<col+offset-1;i++){
                LCD[0][i]=2;
            }
            for(int i=1;i<row-1;i++){
                if(i==(row)/2)continue;
                LCD[i][offset+col-1]=1;
            }
        }
        else if(num=='8'){
            for(int i=offset+1;i<col+offset-1;i++){
                LCD[0][i]=2;
                LCD[row-1][i]=2;
                LCD[(row-1)/2][i]=2;
            }
            for(int i=1;i<row-1;i++){
                if(i==(row)/2)continue;
                LCD[i][offset]=1;
                LCD[i][offset+col-1]=1;
            }
        }
                else if(num=='9'){
            for(int i=offset+1;i<col+offset-1;i++){
                LCD[0][i]=2;
                LCD[row-1][i]=2;
                LCD[(row-1)/2][i]=2;
            }
            for(int i=1;i<row-1;i++){
                if(i==(row)/2)continue;
                if(i<row/2)LCD[i][offset]=1;
                LCD[i][offset+col-1]=1;
            }
        }
    }

    public static void print() {
        for(int i=0;i<LCD.length;i++){
            for(int j=0;j<LCD[i].length;j++){
                if(LCD[i][j]==0)System.out.print(" ");
                else if(LCD[i][j]==1)System.out.print("|");
                else System.out.print("-");
            }
            System.out.println();
        }
        //System.out.println();
    }
}
:D

Post Reply

Return to “Volume 7 (700-799)”