-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bee03d5
commit 7d1a4fc
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package Strings; | ||
|
||
import java.util.Scanner; | ||
|
||
public class RequiredMoves { | ||
|
||
public static int fun(String s){ | ||
int tm = 0; | ||
char prev = 'a'; | ||
char arr[] = s.toCharArray(); | ||
|
||
for(char ch : arr){ | ||
int mini2 = Math.min(prev - 'a' + 'z' - ch + 1 , 'z' - prev + ch - 'a' + 1); | ||
System.out.println(mini2); | ||
int mini = Math.min(Math.abs(ch - prev) , mini2); | ||
|
||
tm += mini + 1; | ||
prev = ch; | ||
} | ||
return tm; | ||
} | ||
public static void main(String args[]){ | ||
|
||
|
||
Scanner sc = new Scanner(System.in); | ||
|
||
String s = sc.next(); | ||
|
||
System.out.println(fun(s)); | ||
|
||
} | ||
|
||
} |