reverseSubstring X88601


Statement
 

pdf   zip   main.cc

html

Implementeu una funció RECURSIVA que rep un string s per referència i dos índexos i, j que cumpleixen 0 <= i <= j < s.size(), i que identifiquen el substring no buit s[i..j]. La funció revessa aquest substring. Aquesta és la capcelera:

// Pre: 0 <= i <= j < s.size()
// Post: el substring s[i..j] s'ha revessat. La resta de s no ha canviat.
void reverseSubstring(string &s, int i, int j);

Observació Només cal enviar el procediment demanat; el programa principal serà ignorat.

Sample session
reverseSubstring(s="aloha", 1, 3) turns s into "ahola"
reverseSubstring(s="abcdefgh", 0, 7) turns s into "hgfedcba"
reverseSubstring(s="abcdefghi", 0, 8) turns s into "ihgfedcba"
reverseSubstring(s="abcdefgh", 1, 6) turns s into "agfedcbh"
reverseSubstring(s="abcdefgh", 1, 7) turns s into "ahgfedcb"
reverseSubstring(s="a", 0, 0) turns s into "a"
reverseSubstring(s="hello", 2, 4) turns s into "heoll"
reverseSubstring(s="aabb", 1, 2) turns s into "abab"
reverseSubstring(s="aabb", 0, 1) turns s into "aabb"
reverseSubstring(s="armaghetton", 7, 8) turns s into "armaghetton"
reverseSubstring(s="superkalifragilistischexpialigetisch", 8, 20) turns s into "superkalcsitsiligarfihexpialigetisch"
Information
Author
PRO1
Language
Catalan
Official solutions
Unknown. This problem is being checked.
User solutions
C++