Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <Windows.h>
- #include <iostream>
- #include <ctime>
- #define SP system("pause");
- #define CLS system("cls");
- using namespace std;
- /*char* getback(const char* word1, char* word2) {
- char* save = word2;
- while (*word2 >= '\0') *word2++ = *word1++;
- return save;
- }*/
- char* strdel1(char* word, int p, int k) {
- int word_str = strlen(word);
- if (p >= word_str || p + k >= word_str) {
- return 0;
- }
- for (int i = p + k; i <= word_str; ++i) {
- word[i - k] = word[i];
- }
- return word;
- }
- char* strdel2(char* word, int p, int k) {
- int word_str = strlen(word), i = p + k;
- if (p >= word_str || i >= word_str) {
- return 0;
- }
- while (i <= word_str) {
- word[i - k] = word[i];
- i++;
- }
- return word;
- }
- char* strdel3(char* word, int p, int k) {
- int word_str = strlen(word), i = p + k;
- if (p >= word_str || i >= word_str) {
- return 0;
- }
- do {
- word[i - k] = word[i];
- i++;
- } while (i <= word_str);
- return word;
- }
- char* strdel4(char* word, int p, int k) {
- char* start = word + p, *end = word + p + k; //берем отрезок от p до k
- int word_str = strlen(word), i = p + k;
- if (p >= word_str || i >= word_str) {
- return 0;
- }
- while (*end != '\0') {
- *start++ = *end++;
- }
- *start = 0;
- return word;
- }
- void testchamber() {
- srand(time(NULL));
- const char* sdel[] = { "Alexander","Germany","Dragon_Maid","9419942","12343","s@11ffs","Enigm@dd","kElH sI5","Ma7","aaab" };
- char stemp[256] = { "" };
- int p = rand() % 5;
- int k = rand() % 6 + 1;
- int test = sizeof(sdel) / sizeof(char*);
- printf("\nFunciton \"STRDEL\" search.test:");
- for (int i = 0; i < test; ++i) {
- printf("\nTest %i:\n", i + 1);
- strcpy(stemp, sdel[i]);
- printf("strdel1 { %s =del=> %s <-- p = %i, k = %i }\n", sdel[i], strdel1(stemp, p, k), p, k);
- strcpy(stemp, sdel[i]);
- printf("strdel2 { %s =del=> %s <-- p = %i, k = %i }\n", sdel[i], strdel2(stemp, p, k), p, k);
- strcpy(stemp, sdel[i]);
- printf("strdel3 { %s =del=> %s <-- p = %i, k = %i }\n", sdel[i], strdel3(stemp, p, k), p, k);
- strcpy(stemp, sdel[i]);
- printf("strdel4 { %s =del=> %s <-- p = %i, k = %i }\n", sdel[i], strdel4(stemp, p, k), p, k);
- }
- }
- int main() {
- const char word1[] = { "Domashniy" };
- char word2[256] = { "" };
- int p = 2;
- int k = 4;
- strcpy(word2, word1);
- printf("Strdel1: { %s }\n", strdel1(word2, p, k));
- strcpy(word2, word1);
- printf("Strdel2: { %s }\n", strdel2(word2, p, k));
- strcpy(word2, word1);
- printf("Strdel3: { %s }\n", strdel3(word2, p, k));
- strcpy(word2, word1);
- printf("Strdel4: { %s }\n", strdel4(word2, p, k));
- testchamber();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement