//Backspace String Compare
//Given two strings $ and T ,
//return if they are equal when both are typed into empty text editors.
//#t means a backspace character
//Example 1:
//Input:S="ab#c",T="ad#c”
//0utput: true
//Explanation:BothSand T become "ac"
//Example 2:
//Input:S ="ab##",T ="c#d#"
//0utput: true
//Explanation:BothS and Tbecome ""
#include <stdio.h>
#include <string.h>
// Helper function to process the backspace character in the string
void processString(char* str, char* result) {
int i, j = 0;
for (i = 0; str[i] != '\0'; i++) {
if (str[i] != '#') {
result[j++] = str[i]; // Add character to result
} else if (j > 0) {
j--; // Simulate backspace by removing the last character
}
}
result[j] = '\0'; // Null terminate the result string
}
int main() {
char S[] = "ab#c";
char T[] = "ad#b#c";
// Arrays to store the final processed strings
char processedS[100];
char processedT[100];
// Process both strings
processString(S, processedS);
processString(T, processedT);
// Compare the processed strings
if (strcmp(processedS, processedT) == 0) {
printf("Output: true\n");
} else {
printf("Output: false\n");
}
return 0;
}