exchange word
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #include <stdio.h> #include <string.h> int main(void) { char Sentence[50] = "Or it's gonna go down in flames"; char target[] = "down"; char exchange[] = "up"; int Target_Length = (int) strlen (target); int index = 0, element = 0; while (Sentence[index] != (char) 0 && element != Target_Length) { int reset = 0; if (Sentence[index++] == target[element]) element++; else if (++reset > 0) { reset = 0; element = 0; } } if (element != Target_Length) return -1; int _index = index, copy = 0; char Next_Sentence[20] ={ (char) 0, }; while (Sentence[_index] != (char) 0) Next_Sentence[copy++] = Sentence[_index++]; _index = index; while (Sentence[_index - element] != (char) 0) Sentence[_index++ - element] = (char) 0; _index = index; int Exchange_Index = 0; while (exchange[Exchange_Index] != (char) 0) Sentence[_index++ - element] = exchange[Exchange_Index++]; _index = index; index = 0; while (Next_Sentence[index] != (char) 0) Sentence[_index++ - element + strlen (exchange)] = Next_Sentence[index++]; printf ("%s\n", Sentence); return 0; } | cs |
0 개의 댓글:
댓글 쓰기