Question

Python Algorithm Coding

There are N paper with three letters written on each paper. Characters are 0 to 9 digits or *.You can create a continuous number by attaching the paper in a proper order. Print out the maximum number of digits sum of a sequence of numbers that can be made when N paper is given.

For example, suppose you have a piece of paper with a lettering as shown below.

3 45

In this case, the consecutive numbers of strings that can be created are as follows:  

12, 126, 12345, 123456, 345, 3456, 6

The largest number of these is 123456, so the answer is 21. (1+2+3+4+5+6)

[Constraint]

1. The number N of paper is not more than 1,000. (1 ≤ N ≤ 1,000)

[Input]

The first line of input gives the total number of test cases T.

From the next line, each test case is given, and the first row is given the number N of paper.

The next line is given three letters written on N paper.

[Output]

The results for test case T are taken "#T" and output the maximum value of the digit agreement among the single space and consecutive numbers.

(T refers to the number of the test case and starts at 1.)

sample input

2
4
*15
7**
402
**3
6
**1
7**
567
24*
8**
234

sample output

#1 19
#2 36

0 0
Add a comment Improve this question Transcribed image text
Answer #1

# read the testcases
testCases = int(input("enter test cases:"))
# function to find max end max start value
def findmax(k,maxValue):
   valueWithoutStar = k.replace("*","")
   valueWithoutStar = int(valueWithoutStar)
   if(maxValue<valueWithoutStar):
       return valueWithoutStar
   else:
       return maxValue
# loop through each test cases and find max available
for i in range(testCases):
   # variables declarations
   maxValue=""
   maxStartValue = 0
   maxEndValue = 0
   # read the no of paper
   papers = int(input("No of papers"))
   strList = list()
   # read the paper values and add it to the list
   for j in range(papers):
       strList.append(input("enter paper value"))
   # loop to find start and end max values
   for k in strList:
       if("*" in k):
           index = k.index("*")
           if(index==0):
               maxEndValue = findmax(k,maxEndValue)
           else:
               maxStartValue = findmax(k,maxStartValue)
   # taked own the remining list of values and add it to the max values
   for k in strList:
       if("*" not in k):
           maxValue+=str(k)
   # now append startmax and remaining values and end max values
   maxValue=str(maxStartValue)+maxValue+str(maxEndValue)
   # type convert each value to int value
   maxValue = [int(k) for k in maxValue]
   # find sum of all digits
   maxValue = sum(maxValue)
   # print each test case max value
   print("#",i+1," ",maxValue,sep="")

Command Prompt Users De1lDesktop>python papersum py nter test cases:2 o of papers4 nter paper value#15 nter paper value?* nte

Sve 1 S we ea Sive A xLSHec has given only one( second 术R T6孑 2ut 2.3 니 6+ +2+3+4t24 y 1 36322424 (nat 76) SIveA wyas 36 10 queston

Add a comment
Know the answer?
Add Answer to:
Python Algorithm Coding There are N paper with three letters written on each paper. Characters are 0 to 9 digits or *.Yo...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python Algorithm Coding There are N paper with three letters written on each paper. Characters are 0 to 9 digits or *.Yo...

    Python Algorithm Coding There are N paper with three letters written on each paper. Characters are 0 to 9 digits or *.You can create a continuous number by attaching the paper in a proper order. Print out the maximum number of digits sum of a sequence of numbers that can be made when N paper is given. For example, suppose you have a piece of paper with a lettering as shown below. In this case, the consecutive numbers of strings...

  • Write a java program 8. I n cryptarithmetic puzzles, mathematical equations are written using letters. Each...

    Write a java program 8. I n cryptarithmetic puzzles, mathematical equations are written using letters. Each letter can be a digit from 0 to 9, but no two letters can be the same. Here is a sample problem: SEND + MORE = MONEY  A solution to the puzzle is S = 9, R = 8, O = 0, M = 1, Y = 2, E = 5, N = 6, D = 7. Write a program that finds a solution...

  • . . In this programming assignment, you need to write a CH+ program that serves as...

    . . In this programming assignment, you need to write a CH+ program that serves as a very basic word processor. The program should read lines from a file, perform some transformations, and generate formatted output on the screen. For this assignment, use the following definitions: A "word" is a sequence of non-whitespace characters. An "empty line" is a line with no characters in it at all. A "blank line" is a line containing only one or more whitespace characters....

  • IN PYTHON 3: In this version of Radix Sort we use Queues very naturally. Let us...

    IN PYTHON 3: In this version of Radix Sort we use Queues very naturally. Let us consider the following set of positive integers: 311, 96, 495, 137, 158, 84, 145, 63 We will sort these numbers with three passes. The number of passes is dependent on the number of digits of the largest number - in this case it is 495. In the first pass we will go through and sort the numbers according to the digits in the units...

  • You're given a chess board with dimension n x n. There's a king at the bottom...

    You're given a chess board with dimension n x n. There's a king at the bottom right square of the board marked with s. The king needs to reach the top left square marked with e. The rest of the squares are labeled either with an integer p (marking a point) or with x marking an obstacle. Note that the king can move up, left and up-left (diagonal) only. Find the maximum points the king can collect and the number...

  • Iwant answer this using number. Airthemitics. Varibles by python This using if else in python The...

    Iwant answer this using number. Airthemitics. Varibles by python This using if else in python The third picture using if. Elif. Else This using for loop in python A. Perimeter of a Rectangle time limit per test 1 second memory limit per test: 256 megabytes input standard input output standard output You are given two positive integers a and b which are the sides of the rectangle. Print the perimeter of this rectangle. The formula for perimeter is P =...

  • Python Problem, just need some guidance with the description, pseudocode and run time. I believe this...

    Python Problem, just need some guidance with the description, pseudocode and run time. I believe this is an 0-1 knapsack problem? Shopping Spree: (20 points) Acme Super Store is having a contest to give away shopping sprees to lucky families. If a family wins a shopping spree each person in the family can take any items in the store that he or she can carry out, however each person can only take one of each type of item. For example,...

  • I want this using while loop This using stringin python Use list or some thing in...

    I want this using while loop This using stringin python Use list or some thing in python Using list in python I want answer as soon as posdible E. Last Number time limit per test: 1 second memory limit per test: 256 megabytes input standard input output standard output You are given a sequence of positive integers aj, , 03, ... Print the last element of the sequence. Input The input consists of multiple lines. The i-th line contains a...

  • Write a C program which calculates how many digits a number has and prints each digit...

    Write a C program which calculates how many digits a number has and prints each digit in reserve order with space in between(no space after the last digit). The number > 0 and has no more than 5 digits. (optional] It is better to write two functions. One is designed for printing number in reverse order and the other is for counting the number of digits. Given that the value of number (which is an int variable) is 12345, the...

  • In python, write the following program, high school question, please keep simple. When I submitted the...

    In python, write the following program, high school question, please keep simple. When I submitted the solution, I get an error as 'wrong answer'. Please note below the question and then the solution with compiler errors. 7.2 Code Practice: Question 2 Instructions Write a program to generate passwords. The program should ask the user for a phrase and number, and then create the password based on our special algorithm. The algorithm to create the password is as follows: If the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT