Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- setlocal enabledelayedexpansion
- set /p string1=Enter the first string to compare:
- echo.
- set /p string2=Enter the second string to compare:
- ::remove spaces from the text
- set s1=!string1: =!
- set s2=!string2: =!
- ::First find the length of each. Makes for a really easy check if they're not the same if they have different lengths.
- for /l %%a in (0,1,100000) do (
- set total1=%%a
- if "!s1:~%%a,1!"=="" goto next1
- )
- :next1
- for /l %%b in (0,1,100000) do (
- set total2=%%b
- if "!s2:~%%b,1!"=="" goto next2
- )
- :next2
- if "!total1!"=="!total2!" goto next3
- call :nomatch
- ::check that the first character of the first string can be found in the second string
- :next3
- for /l %%c in (0,1,%total2%) do (
- set pos2=%%c
- if /i "!s2:~%%c,1!"=="!s1:~0,1!" goto next4
- if "%%c"=="%total2%" goto nomatch
- )
- ::This section removes the character from both the strings.
- :next4
- set /a num1=%total2% - %pos2% -1
- set /a num2=%pos2% + 1
- set temp1=!s2:~0,%pos2%!
- set temp2=!s2:~%num2%,%num1%!
- set s2=!temp1!!temp2!
- set /a total1=%total1% - 1
- if "%total1%"=="0" goto match
- set s1=!s1:~1,%total1%!
- goto next3
- :nomatch
- echo No, the characters cannot be rearranged to match.
- pause > nul
- exit /b
- :match
- setlocal disabledelayedexpansion
- echo Yes! The characters can be rearranged to match!
- pause>nul
- exit /b
Advertisement
Add Comment
Please, Sign In to add comment