-
Notifications
You must be signed in to change notification settings - Fork 226
Task12 #813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Task12 #813
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c83ea1a
?
stillwearit 2810432
готово?
stillwearit 8287262
пробуем
stillwearit 0d3b71a
пробуем
stillwearit 39521db
пробуем
stillwearit 892435c
пробуем
stillwearit c9bfb7c
пробуем
stillwearit 1a9a050
пробуем
stillwearit b6589e0
исправила
stillwearit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| package com.walking.intensive.chapter3.task12; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Scanner; | ||
|
|
||
| /** | ||
| * Девочка Света очень любит играть в мячики. Она поставила в ряд корзинки и в некоторые положила по 1 мячику. | ||
| * За 1 раз она может переложить 1 мячик в соседнюю корзинку. В 1 корзинке может поместиться много мячиков. | ||
|
|
@@ -40,11 +43,39 @@ | |
| */ | ||
| public class Task12 { | ||
| public static void main(String[] args) { | ||
| // Для собственных проверок можете делать любые изменения в этом методе | ||
| Scanner in = new Scanner(System.in); | ||
| System.out.print("Введите данные: "); | ||
| String baskets = in.nextLine(); | ||
| in.close(); | ||
|
|
||
| System.out.print(Arrays.toString(getMovementsNumber(baskets))); | ||
|
|
||
| } | ||
|
|
||
| static int[] getMovementsNumber(String baskets) { | ||
| // Ваш код | ||
| return new int[]{}; | ||
| int basketsAmount = baskets.length(); | ||
| char[] basketsArray = new char[basketsAmount]; | ||
|
|
||
| for (int i = 0; i < basketsArray.length; i++) { | ||
| basketsArray[i] = baskets.charAt(i); | ||
| if (!isValid(basketsArray[i])) { | ||
| return new int[]{}; | ||
| } | ||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Логичнее было бы все, вместе с циклом, вынести в boolean-метод isValid(). И если результат false - возвращать пустой массив. Но текущий вариант тоже имеет право на жизнь |
||
|
|
||
| int[] actionsAmount = new int[basketsAmount]; | ||
| for (int i = 0; i < actionsAmount.length; i++) { | ||
| for (int j = 0; j < actionsAmount.length; j++) { | ||
| if (basketsArray[j] == '1') { | ||
| actionsAmount[i] += Math.abs(i - j); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return actionsAmount; | ||
| } | ||
|
|
||
| static boolean isValid(char a) { | ||
| return a == '1' || a == '0'; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.