Error code
#include <iostream>#include<string>using namespacestd;BOOLIslow (Charc) { if((c>='A') && (c<='Z')) return false; Else return true;}BOOLIsCap (Charc) { return!Islow (c); }intMain () {strings; while(cin>>s) {intn=s.size (); intL=0, r=n-1; while(l<r) { while(r>=0&& IsCap (S[r])) r--;//a lowercase letter at the far right of R while(l<=n-1&& Islow (S[l])) l++;//l point to the left-most uppercase letter if(l<r) Swap (S[l],s[r]); Else Break; } cout<<s<<Endl; }}
Test Cases
Test Case: Hxklagllzpytxsfsrunnskqbhdqqroyaeyjrgijbhidxfcqkfmihpnkibfhxxdbdkavgziblvwnlxjahmttssjkzhsmqnenvokoiyzrjpqsrffaaqzbynyerj Vkvfrcgdfycidtqbyqcpatdrgzzbaakoqybwmoyhrcqdwcrwqqpqavtnabjrivwxjortyjvgyswzkyenagqbzkjlucabnyvyvfxagklfqhxnttaqzfncedtro Gmzzndbvzbbarbjvuyivlwrkaagrvtyxrscuoqxdwcrmveedrlkzkfjvrmrlsmbmogujyfdzirfhuswjqgrtymlxkqnmacavatlqirzmfqvywgqtvenxucpkq Cauqbjyfanuwondtbnldgrtpucqodqsujoddpuczjwczaasddeyjkvitumhrcmzqslrjiefvisatiutfxbeknhpyvwukzrlifsywgexogiegxdbfxaybwfuqf Yevjfihepdpkqeigutzhddidbgkpvbfyqheeehatoabqhepidihigbtwjghiqrctzxqqykffowubqzyicjrpqbilhrnqnbzfmoruycsrgkawjccormceegisp Ipsgvjbngwvmtytgoalqfpfyofaxndjznfkdtwfixisktjyjchidxpyglfobolriuiahmabqwohbgbduybhldqgzjasshszoepthlvnybnqwegmonexfdstvy The hgtdmlyugefobsqmgndboxkkhvhfvryoovoyxdjqjljysngksbtopopjfskqzheplukxyytycew corresponding output should be: Hxzyxssrnndryagibckmhfxdvgiwnlxmttskhmneoojqsraaqbyyejrdfycidqbycptdzzaoqybyhrdwcwpavnbjriwxrzeqzkucabvyxfqttaqfncdroznbv AbvuvlraarvtyxrsqxdwrmermrsmbmyfdrhuwxaavatlmvygxcabjyfauwodldgrtCodqsudpczaasdkviturmljefisattfxenyvzlisgeogigbfxybwuqyvjfqithdpvyqehobqpdhtjictxkfobqycjilrnqzmorkawcrceegppjbngtolyxndf Wxisjyjchidpgforiumbwogbdlsszthnbqegmexfdsgtmlyugefsqmgoxkkhfvrooyxjngksboposzeukyeklagllptfuskqbhqqoeyjrjhidxfqfipnkibhx Dbkazblvjahsjzsqnvkiyzrpffznrvkvfcgtqargbakwmocqrqqqtavjotyjvgyswkynagbjlnyvfagklhxnzetgmzdzbbrjyiwkgcuocvedlkzkfjvrloguj Zifsjqgrtymlkqnmcqirzfqwqtvenupkqcuqnntbnpuqjodujwczdeyjmhczqsriviubkhpwukrfywxexdaffeihepdpkeguzdidbgkbfheeataheiiigbwgh Qrzqqyfwuzirpqbhnbfruycsgjcomisisgvwvmtygaqfpfofajznkdtfiktxylboliahaqhbuybhdqgzjashoeplvynwontvyhdobndbvhyvodjqjlystpjfk QHPLXYTYCW your output is: Hxeykuezzsyoxspsronnbskgndjxryyaoorvgifbhkkxocgkmmqhsfegufyxlmtdgsvgdifxewnlxmgemttsqbknhhmtnezsosoldbgjoqsrwbaaqmbyuyeij Rofgrpddfycidiqbyhcpctdjyzzjsaioqybxwfyhrdndwcxwylpoavtngbjrinwxbjrppgeecrczwaekroqmzkzqucabnrvylixjcyqfqbofttaqkfncxdtro Cizjntbvhdpaqbbvuohvlerqaayrvtyxrsvpdqxdwhrmtieqrfjvyquwbmrysmbmxfbgyfdigrohuewgsilzvynxexftatavatlasifmejvylgmrutixvckds AaazbjyfacuwopddUsldgrtqdcoqupnbjotdnunqjwczucqdkeyjpunevmhtcqzqswrqifzvriqciumnqbkklhpmywuktrrgfqywjsxfizejxdugoalrvfjffkezklihepdpkdeeg Uvzcodidbgkucbfgkhweeiatyajrhebibizigbdwzghmqrgtzeqqyznfxwuhlzkigarpqbfvhynlnbjfbgruycsagnykjcwosmygvjisyitsgvojvawvmtytg Qaqqfpfqofarqcjznokdtmfiwkaktbgraqtgxcyflvkbolvrniahzafqfphbrzyuybhidqgzjaskhvnoepqslvzyjnswhajonvlbzatvyhkbddxhbiknobpif Qndbfxdihvhjrjyyevooqdjqjlqyshbqkstuftpjfpkqlhlplgaxlytyckw
[Interview programming questions] Algorithm basics-character shift