Tuesday, April 26, 2016

URI Online Judge Solution 1168 || LED

Main Link: https://www.urionlinejudge.com.br/judge/en/problems/view/1168

URI Online Judge | 1168

LED

Unknown Author
Timelimit: 1
John wants to set up a panel containing different numbers of LEDs. He does not have many leds, he is not sure if he will be able to mount the desired number. Considering the configuration of the LEDs of the numbers below, make an algorithm that helps John to discover the number of LEDs needed to set the value.

Input

The input contains an integer N, (1 ≤ N ≤ 2000) corresponding to the number of test cases, followed by N lines, each line containing a number (1 ≤ V ≤ 10100corresponding to the value that John wants to set with the leds.

Output

For each test case, print one line containing the number of LEDs that John needs to set the desired value, followed by the word "leds".
Input SampleOutput Sample
3
115380
2819311
23456
27 leds
29 leds
25 leds

URI 1168 Solution in C Language || LED


#include <stdio.h>
#include <string.h>
 
int main () {
    int i, length ,n;
    char str[100];
    int total;
    scanf("%d",&n);
    while(n--){
        scanf("%s",str);
        length = strlen(str);
 
        for(i = 0, total = 0; i < length; i++) {
            if(str[i] == '0')
                total += 6;
            else   if(str[i] == '1')
                total += 2;
            else if(str[i] == '2')
                total += 5;
            else  if(str[i] == '3')
                total += 5;
            else   if(str[i] == '4')
                total += 4;
            else   if(str[i] == '5')
                total += 5;
            else  if(str[i] == '6')
                total += 6;
            else  if(str[i] == '7')
                total += 3;
            else  if(str[i] == '8')
                total += 7;
            else  if(str[i] == '9')
                total += 6;
        }
        printf("%d leds\n", total);
    }
    return 0;
}



URI 1168 Solution in C++ Language || LED

#include <iostream>
#include <cstring>
using namespace std;
 
int main(int argc, char const *argv[])
{
    int x, tmp, size;
    string s;
    cin >> x;
 
    for (int i = 0; i < x; ++i)
    {
        tmp = 0;
        cin >> s;
        size = s.length();
 
        for (int j = 0; j < size; ++j)
        {
            if(s[j] == '0' || s[j] == '9' || s[j] == '6'){
                tmp += 6;
            }else if(s[j] == '1'){
                tmp += 2;
            }else if(s[j] == '2' || s[j] == '3' || s[j] == '5'){
                tmp += 5;
            }else if(s[j] == '4'){
                tmp += 4;
            }else if(s[j] == '7'){
                tmp += 3;
            }else{
                tmp += 7;
            }
        }
 
        cout << tmp << " leds" << endl;
    }
    return 0;
}

URI 1168 Solution in JAVA Language || LED(not verified can skip this)

package uri_java_problem_solution;

import java.util.Scanner;

public class LED {

public static void main(String[] args) {
int takeValue, testCase;
int ledValue[] = {6,2,5,5,4,5,6,3,7,6};

Scanner sc =new Scanner(System.in);

testCase = sc.nextInt();
for (int i = 1; i <= testCase; i++) {
int everyValue = 0,totalLed = 0;
takeValue = sc.nextInt();

while (takeValue != 0) {
everyValue =(takeValue % 10);
takeValue /= 10;
totalLed += ledValue[everyValue];
}
System.out.println(totalLed+" leds");
}
}

}


No comments:
Write comments

To know more about the problem, give us your valuable commment. We'll try to help you. Thanks

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.