xoox | transform, anything
kandi X-RAY | xoox Summary
kandi X-RAY | xoox Summary
transform, anything
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of xoox
xoox Key Features
xoox Examples and Code Snippets
Community Discussions
Trending Discussions on xoox
QUESTION
I'm trying to make a method that takes in an integer parameter with user input, checks whether it's odd or even, and then creates a corresponding pattern of x's and o's depending on which it is. The amount of rows and columns is equal to the value of the parameter as well.
The pattern that should be output if the parameter is odd is a cross. It if equals 5 it should look like this:
...ANSWER
Answered 2021-May-21 at 18:28The condition in your if
for the method to print the cross pattern is easy:
- The diagonal that goes from top-left to bottom-right is trivial, because the condition for the 'x' to print is simply
j == i
. - The other diagonal in the first row must print the 'x' when
j == 4
orj == intIn - 1
, the second row whenj == 3
orj == intIn - 2
, etc. Therefore, this condition also depends on the current rowi
but in a descending way. You can deduce from this that the condition for the second diagonal isj == intIn - i - 1
.
The final code is:
QUESTION
You might have seen a strip of cable across the road that the DOT uses to count vehicles passing by that road each day. It counts each change in pressure as an axle. Small (car), medium (pickups and vans) and large (trucks) vehicles have different axle patterns so that the DOT can distinguish what kind of vehicles pass by in addition to the number of each.
Write a program that will emulate this car counter. For this program, there will be a continuous string of characters (split up in 10 lines of 50 characters each) in which “x” will represent space between bumps and the “o” will represent a “bump” of an axle. Small vehicles will have the pattern “oo” surrounded by any number of x’s. Medium vehicles will have the pattern “oxo” surrounded by x’s. Large vehicles will have the pattern “oxoxxooo”. To make it easier, a vehicle will not be split across different lines of data. For example, the following represents 2 small vehicles, followed by 2 medium vehicles, and lastly one large vehicle: xooxxxxooxxxxoxoxxxxoxoxxxxxxxoxoxxoooxxxxxxxxxxxx
Input:
There are 10 lines of data, each 50 characters long.
line1 = “xooxxxxooxxxxoxoxxxxoxoxxxxxxxoxoxxoooxxxxxxxxxxxx”
line2 = “ooxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”
line3 = “oxoxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”
line4 = “oxoxxoooxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”
line5 = “xxxoxoxxoooxxxxxxoxoxxoooxxxxxxxxoxoxxoooxxxxxxxxx”
line6 = “xoxoxxoooxxxxxooxxxooxxooxxooxxxxxooxxxxooxxxxooxx”
line7 = “oxoxxoxoxxoxoxxoxoxxoxoxxxxxxxoxoxxxxxoxoxxxxxoxox”
line8 = “xooxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxoo”
line9 = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”
line10 = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxoxoxxooo”
Output:
12 small
11 medium
7 large
Here's what I've got so far but I couldn't print the output I wanted:
...ANSWER
Answered 2019-Mar-03 at 15:41This would be a good application of regular expressions. Also, the Counter object from the collection modules will help with the tally:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install xoox
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page