Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.*;
- public class Problem {
- public static void main(String[] args){
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- String number = sc.next();
- int result = minimiseMoves(number, n);
- System.out.println(result);
- }
- public static int minimiseMoves(String number, int n) {
- int moves = 0;
- moves += (number.charAt(n-1) - '0');
- for(int i=0; i < n-1; i++){
- if(number.charAt(i) != '0')
- moves += (number.charAt(i) - '0' + 1);
- }
- return moves;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement