GL1TCH3D

Checking characters

Jan 21st, 2016
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. @echo off
  2. setlocal enabledelayedexpansion
  3.  
  4. set /p string1=Enter the first string to compare:
  5. echo.
  6. set /p string2=Enter the second string to compare:
  7.  
  8. ::remove spaces from the text
  9.  
  10. set s1=!string1: =!
  11. set s2=!string2: =!
  12.  
  13. ::First find the length of each. Makes for a really easy check if they're not the same if they have different lengths.
  14.  
  15. for /l %%a in (0,1,100000) do (
  16. set total1=%%a
  17. if "!s1:~%%a,1!"=="" goto next1
  18. )
  19.  
  20. :next1
  21.  
  22. for /l %%b in (0,1,100000) do (
  23. set total2=%%b
  24. if "!s2:~%%b,1!"=="" goto next2
  25. )
  26.  
  27. :next2
  28. if "!total1!"=="!total2!" goto next3
  29. call :nomatch
  30.  
  31.  
  32. ::check that the first character of the first string can be found in the second string
  33. :next3
  34. for /l %%c in (0,1,%total2%) do (
  35. set pos2=%%c
  36. if /i "!s2:~%%c,1!"=="!s1:~0,1!" goto next4
  37. if "%%c"=="%total2%" goto nomatch
  38. )
  39.  
  40. ::This section removes the character from both the strings.
  41. :next4
  42. set /a num1=%total2% - %pos2% -1
  43. set /a num2=%pos2% + 1
  44. set temp1=!s2:~0,%pos2%!
  45. set temp2=!s2:~%num2%,%num1%!
  46. set s2=!temp1!!temp2!
  47. set /a total1=%total1% - 1
  48. if "%total1%"=="0" goto match
  49. set s1=!s1:~1,%total1%!
  50. goto next3
  51.  
  52. :nomatch
  53. echo No, the characters cannot be rearranged to match.
  54. pause > nul
  55. exit /b
  56.  
  57. :match
  58. setlocal disabledelayedexpansion
  59. echo Yes! The characters can be rearranged to match!
  60. pause>nul
  61. exit /b
Advertisement
Add Comment
Please, Sign In to add comment