[ create a new paste ] login | about

Link: http://codepad.org/WbbnWCZS    [ raw code | output | fork ]

C++, pasted on Dec 1:
#include <stdio.h>
#include <string.h>
#include <ctype.h>




//Занести в выходную строку все слова исходной строки, которые отличны от последнего слова.
char* task0(char* d, char* s) {
	char* t = d;
	char* a, *b;

	for(b = s + (strlen(s) - 1); (b > s) && (! isalpha(*b)); *b--);
	for(a = b; (a > s) && (isalpha(*a)); *a--);
	++a;

	while(s < a) {
		if(isalpha(*s)) {
			if(! strncmp(s, a, b - a)) {
				if(! isalpha(*(s + (b - a) + 1))) {
					s += (b - a) + 1;
					continue;
				}
			}
		}
		*d++ = *s++;
	}
	*d = '\0';
	return t;
}




//Перед каждым словом, начинающимся с буквы 'a' добавить слово "вот".
char* task3(char* s, char c, const char* r) {
	char* t  = s;
	size_t n = strlen(r);

	while(*s) {
		if(isalpha(*s)) {
			if(*s == c) {
				memmove(s + n, s, strlen(s) - n);
				strncpy(s, r, n);
				s += n + 1;
			}
			while(*s && (isalpha(*s)))
				*s++;
		} else
		    *s++;
	}
	return t;
}





int main(){

	char s[64] = "the bot bla-bot asp, the apple bottle bot.";
	char d[64];

	task0(d, s);
	puts(d);

	task3(s, 'a', "vot ");
	puts(s);
    return 0;
}


Output:
1
2
the  bla- asp, the apple bottle 
the bot bla-bot vot asp, the vot apple bot


Create a new paste based on this one


Comments: