Maksym Yakushev
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Учебная практика 2021. Codewars Day1. 05.07.2021. Якушев Максим Дмитриевич. *** 1. Присутствовал на онлайн лекции / практике. 2. Решил 4 задачи. ### Задача. Twice as old. 8kyu (https://www.codewars.com/kata/5b853229cfde412a470000d0). Ваша функция принимает два аргумента: 1.текущий возраст отца (лет) 2.текущий возраст сына (лет) Подсчитайте, сколько лет назад отец был вдвое старше своего сына (или через сколько лет он будет вдвое старше). ### Решение на языке C++ ```c= int twice_as_old(int dad, int son) { return abs(son*2 - dad); } ``` ### Решение на языке Java ```java= public class TwiceAsOld{ public static int TwiceAsOld(int dadYears, int sonYears){ return Math.abs(sonYears*2-dadYears); } } ``` ### Задача. Convert a Number to a String! 8kyu (https://www.codewars.com/kata/5265326f5fda8eb1160004c8) Нам нужна функция, которая может преобразовывать число в строку.Какие способы добиться этого вы знаете? ``` Примеры: 123 -> «123» 999 -> «999» ``` ### Решение на языке C++ ```c= #include <string> using namespace std; string number_to_string(int num) { return to_string(num); } ``` ### Решение на языке Java ```java= class Kata { public static String numberToString(int num) { return Integer.toString(num); } } ``` ### Задача. Reverse a Number. 7kyu (https://www.codewars.com/kata/555bfd6f9f9f52680f0000c5) Для данного числа напишите функцию для вывода его обратных цифр. (например, если дано 123, ответ будет 321).Числа должны сохранять свой знак; то есть отрицательное число должно быть отрицательным при обратном. ``` Примеры: 123 -> 321 -456 -> -654 1000 -> 1 ``` ### Решение на языке C++. ```с= long long reverseNumber(long long n) { int res = 0; while(n != 0) { res = res * 10 + n% 10; n /= 10; } return res; } ``` ### Решение на языке Java ```java= public class ReverseNumber { public static int reverse(int number) { int res = 0; while(number != 0) { res = res * 10 + number % 10; number /= 10; } return res; } } ``` ### Задача. Happy Birthday, Darling! 7 kyu (https://www.codewars.com/kata/5e96332d18ac870032eb735f) Как вы, возможно, знаете, когда некоторые люди достигают подросткового возраста, они в шутку празднуют только 20 или 21 день рождения, навсегда. С некоторыми математическими навыками это вполне возможно - вам нужно только выбрать правильную числовую основу! Например, если им исполняется 32 года, это ровно 20 - по основанию 16 ... Уже 39? Это всего 21, в базе 19! Ваша задача - перевести заданный возраст в желанные 20 (или 21) год и указать основание счисления в формате, указанном ниже. Примечание: ввод всегда будет > 21 ``` Пример: 32 --> "32? That's just 20, in base 16!" 39 --> "39? That's just 21, in base 19!" ``` ### Решение на языке С++ ```c= #include <string> using namespace std; string womens_age(unsigned n) { if(n%2 == 0){ return to_string(n) + "? That's just 20, in base " + to_string(n/2) + "!" ; } else { return to_string(n) + "? That's just 21, in base " + to_string(n/2) + "!" ; } } ``` ### Решение на языке Java ```java= public class Kata { public static String womensAge(int n) { String s = ""; if (n % 2 == 0) { s = n + "? That's just 20, "; } else { s = n + "? That's just 21, "; } n = (int) (n / 2); return s + "in base " + n + "!"; } } ``` ## Задача. Minimum Ticket Cost. 7kyu (https://www.codewars.com/kata/5bdc1558ab6bc57f47000b8e) Несколько лет назад Аарон покинул свою старую школу и поступил в другой из соображений безопасности. Теперь он хочет найти Джейн, одну из своих одноклассниц и хороших друзей. Всего имеется n школ, пронумерованных от 1 до n. Между каждой парой школ можно путешествовать, купив билет. Билет между школами i и j стоит (i + j) по модулю (n + 1) и может использоваться несколько раз. Помогите Аарону определить минимальную общую стоимость посещения всех школ. Он может начать и закончить в любой школе. ### Решение на языке С++ ```c= ``` ### Решение на языке Java ```java= ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully