363A - Soroban - CodeForces Solution


implementation *800

Please click on ads to support us..

Python Code:

import collections
import heapq
import sys
import math
import itertools
import bisect
from io import BytesIO, IOBase
import os
def valid(i,j,n,m):
        if i<n and i>=0 and j>=0 and j< m :return True         return  False
def sumn(i,n):
    return (n-i)*(i+n)/2
def sqfun(a,b,c):
    return (-b+math.sqrt(b*b-4*a*c))/2*a
def getprime(num):     
        if  all(num%i!=0 for i in range(2,int(math.sqrt(num))+1)):return  True
           


def value(): return tuple(map(int, input().split()))
def values(): return tuple(map(int, sys.stdin.readline().split()))
def inlst(): return [int(i) for i in input().split()]
def inlsts(): return [int(i) for i in sys.stdin.readline().split()]
def inp(): return int(input())
def inps(): return int(sys.stdin.readline())
def instr(): return input()
def stlst(): return [i for i in input().split()]



def solve():
    n = inp()
    for i in str(n)[::-1]:
        tmp=int(i)
        s=''
        if tmp>=5:
            s+='-O|'
            s+='O'*(tmp-5)+'-'
            s+='O'*(5-(tmp-5)-1)
        else:
            s+='O-|'
            s+='O'*(tmp)+'-'
            s+='O'*(5-(tmp)-1)
        print(s)





if __name__ == "__main__":
            solve()

C++ Code:

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    if(n==0)
    {
        cout<<"O-|-OOOO"<<"\n";
        return 0;
    }
    while(n)
    {
        int r=n%10;
        if(r>4)
        {
            cout<<"-O|";
            int l=r-5;
            int c=l;
            while(l>0)
            {
                cout<<"O";
                l--;
            }
            int m=4-c;
            cout<<"-";
            while(m>0)
            {
                cout<<"O";
                m--;
            }
        
        }
        else
        {
            cout<<"O-|";
            int l=4-r;
            int m=l;
            while(r>0)
            {
                cout<<"O";
                r--;
            }
          
            cout<<"-";
            while(m>0)
            {
                cout<<"O";
                m--;
            } 
        }
        n/=10;
        cout<<"\n";
    }
    cout<<"\n";
    return 0;
}


Comments

Submit
0 Comments
More Questions

1424M - Ancient Language
600C - Make Palindrome
1669D - Colorful Stamp
1669B - Triple
1669A - Division
1669H - Maximal AND
1669E - 2-Letter Strings
483A - Counterexample
3C - Tic-tac-toe
1669F - Eating Candies
1323B - Count Subrectangles
991C - Candies
1463A - Dungeon
1671D - Insert a Progression
1671A - String Building
1671B - Consecutive Points Segment
1671C - Dolce Vita
1669G - Fall Down
4D - Mysterious Present
1316B - String Modification
1204A - BowWow and the Timetable
508B - Anton and currency you all know
1672A - Log Chopping
300A - Array
48D - Permutations
677C - Vanya and Label
1583B - Omkar and Heavenly Tree
1703C - Cypher
1511C - Yet Another Card Deck
1698A - XOR Mixup