Algorithm
Problem Name: beecrowd | 2749
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2749
Output 3
By Roberto A. Costa Jr, UNIFEI Brazil
Timelimit: 1
Your teacher would like to make a screen with the following characteristics:
- Have 39 dashes (-) on the first line;
- Have a | underneath the first dash and the thirty-ninth dash of the first line, below the 2nd dash you should start typing "x = 35" and the rest fill in with whitespace;
- Have a | below the first dash and the thirty-ninth dash of the first line, fill in the middle with whitespace;
- Have a | below the first dash and the thirty-ninth dash of the first line, below the 17th dash you should start typing "x = 35" and the rest fill in with whitespace;
- Repeat procedure 3;
- Have a | under the first dash and the thirty-ninth dash of the first line, under the 33rd dash you should start typing "x = 35" and the rest fill in the middle with whitespace;
- Repeat procedure 1.
At the end should look like the following image:
--------------------------------------- (39 dashes)
|x = 35 |
| |
| x = 35 |
| |
| x = 35|
--------------------------------------- (39 dashes)
Input
There is not.
Output
The output will be printed as shown above.
Input Sample | Output Sample |
--------------------------------------- |x = 35 | | | | x = 35 | | | | x = 35| --------------------------------------- |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
int main() {
printf("---------------------------------------\n");
printf("|x = 35 |\n");
printf("| |\n");
printf("| x = 35 |\n");
printf("| |\n");
printf("| x = 35|\n");
printf("---------------------------------------\n");
}
Copy The Code &
Try With Live Editor
Output
#2 Code Example with C++ Programming
Code -
C++ Programming
#include <iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iterator>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<cstdio>
#include<stack>
#include<queue>
#include<math.h>
#include <utility>
#include <sstream>
#include<bitset>
using namespace std;
typedef long long ll;
typedef std::vector < double> vi;
#define PI acos(-1)
#define E 2.718281828459
int main(int argc, char** argv) {
printf("---------------------------------------\n");
printf("|x = 35 |\n");
printf("| |\n");
printf("| x = 35 |\n");
printf("| |\n");
printf("| x = 35|\n");
printf("---------------------------------------\n");
}
Copy The Code &
Try With Live Editor
Output
#3 Code Example with Java Programming
Code -
Java Programming
public class Main {
public static void main(String[] args) {
System.out.printf("---------------------------------------\n");
System.out.printf("|x = 35 |\n");
System.out.printf("| |\n");
System.out.printf("| x = 35 |\n");
System.out.printf("| |\n");
System.out.printf("| x = 35|\n");
System.out.printf("---------------------------------------\n");
}
}
Copy The Code &
Try With Live Editor
Output
#4 Code Example with Javascript Programming
Code -
Javascript Programming
"use strict"
const isSuccessfullyDefined = Reflect.defineProperty(String.prototype, "pad", {
value(pad, from = 0) {
const splited = [...this]
splited.splice(from, pad.length, ...pad)
return splited.join("").substr(0, this.length)
},
writable: false,
configurable: false,
enumerable: true,
})
const ROW_SIZE = 39
const SPACE = " "
const DIV = "|"
const DASH = "-"
function main() {
const separator = DASH.repeat(ROW_SIZE)
const row = SPACE.repeat(ROW_SIZE)
.pad(DIV, 0)
.pad(DIV, -1)
const output = [
separator,
row.pad("x = 35", 1),
row,
row.pad("x = 35", 16),
row,
row.pad("x = 35", 32),
separator,
]
console.log(output.join("\n"))
}
if (isSuccessfullyDefined) {
main()
}
Copy The Code &
Try With Live Editor
Output
#5 Code Example with Python Programming
Code -
Python Programming
tam = 39
for i in range(tam):
print('-', end = '')
print()
print('|x = 35', end = '')
for i in range(tam-8):
print(' ', end = '')
print('|')
print('|', end = '')
for i in range(tam-2):
print(' ', end = '')
print('|')
print('| x = 35', end = '')
for i in range(tam-23):
print(' ', end = '')
print('|')
print('|', end = '')
for i in range(tam-2):
print(' ', end = '')
print('|')
print('|', end = '')
for i in range(tam-8):
print(' ', end = '')
print('x = 35|')
for i in range(tam):
print('-', end = '')
print()
Copy The Code &
Try With Live Editor
Output