DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Curious about the future of data-driven systems? Join our Data Engineering roundtable and learn how to build scalable data platforms.

Data Engineering: The industry has come a long way from organizing unstructured data to adopting today's modern data pipelines. See how.

Threat Detection: Learn core practices for managing security risks and vulnerabilities in your organization — don't regret those threats!

Managing API integrations: Assess your use case and needs — plus learn patterns for the design, build, and maintenance of your integrations.

Trending

  • How Jenkins Can Stay Relevant in the Next Decade
  • Optimizing Vector Search Performance With Elasticsearch
  • Front-End Debugging, Part 1: Not Just Console Log
  • Lifecycle Microservices With GenAI Tools

A Solution For The "LCD Display" Problem

By 
Snippets Manager user avatar
Snippets Manager
·
Mar. 18, 08 · Code Snippet
Likes (0)
Comment
Save
Tweet
Share
4.8K Views

Join the DZone community and get the full member experience.

Join For Free
A solution for the "LCD Display" problem.
 
Problem description:
http://acm.uva.es/p/v7/706.html

Author: Joana Matos Fonseca da Trindade
Date: 2008.03.09


/* 
 * Solution for the "LCD Display" problem.
 * UVa ID: 706
 */
#include 
#include 
#include 

#define MAX_SIZE 9

int main (int argc, const char * argv[]) {
	/* number of vertical or horizontal segments in each digit */
	int s;
	
	/* the number to print */
	char digitString[MAX_SIZE];
	
	/* 
	 * LED representation for each number, according to 
	 * the following convention:
	 *
	 *  -0-
	 * |   |
	 * 2   1
	 * |   |
	 *  -3-
	 * |   |
	 * 5   4
	 * |   |
	 *  -6-
	 *
	 */
	
	const char conversionTable[10][7] = {
		      /* 0   1   2   3   4   5   6 */
		/* 0 */ '-','|','|',' ','|','|','-',	  
		/* 1 */ ' ','|',' ',' ','|',' ',' ',
		/* 2 */ '-','|',' ','-',' ','|','-',
		/* 3 */ '-','|',' ','-','|',' ','-',
		/* 4 */ ' ','|','|','-','|',' ',' ',
		/* 5 */ '-',' ','|','-','|',' ','-',
		/* 6 */ '-',' ','|','-','|','|','-',
		/* 7 */ '-','|',' ',' ','|',' ',' ',
		/* 8 */ '-','|','|','-','|','|','-',
		/* 9 */ '-','|','|','-','|',' ','-',

	};
	
	/* iterators */
	int i, j, k;
	
	while(scanf("%d %s", &s, &digitString) != EOF) {
		
		/* 0, ends the program */
		if (!s) {
			return 0;
		}
		
		int n = strlen(digitString);
		int digit;
		
		for (i = 0; i < 2*s+3; i++) {					
			for (j = 0; j < n; j ++) { 
						
				digit = digitString[j] - '0';

				/* upper, middle and lower parts */
				if ((i % (s + 1)) == 0) {
					printf(" ");
					for (k = 0; k < s; k++) {
						printf("%c", conversionTable[digit][(i / (s + 1)) * 3]);
					}
					printf(" ");
				}
				
				/* between upper and middle parts */
				if (i > 0 && i < (s + 1)) {
					printf("%c", conversionTable[digit][2]);
					for (k = 0; k < s; k++) {
						printf(" ");
					}
					printf("%c", conversionTable[digit][1]);
				}

				
				/* between middle and lower parts */
				if (i > (s + 1) && i < (2*s + 2)) {
					printf("%c", conversionTable[digit][5]);
					for (k = 0; k < s; k++) {
						printf(" ");
					}
					printf("%c", conversionTable[digit][4]);
				}
				
				/* if not the last number */
				if (j != n-1)
					printf(" ");
	
			}			
			printf("\n");
			
		}
		printf("\n");
		
	}
	
	return 0;
}

Opinions expressed by DZone contributors are their own.

Partner Resources


Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: