//Дана строка слов. Сформируйте новую строку, вставив перед каждым из слов "а" и "но" запятую. //Подсчитайте количество подстрок, разделенных запятыми. //Сформируйте строку из слов, с которых начинаются подстроки. #include "stdafx.h" #include <string.h> #include <iostream> #include <conio.h> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { char str[80], new_str[160], last_str[80]; int new_n_last_count=0, a=0; cout << "input the string" << endl; cin.get(str, 80); for (int i=0; i<strlen(str); i++) { //while (str[i] == ' ' && (str [i+1] == ' ' || i == strlen(str)-1)) continue; while (str[i] == '/0') continue; if (str[i] == 'a' && str[i-1] == ' ' && str[i+1] == ' ') {new_str[i+new_n_last_count]=','; new_n_last_count++; new_str[i+new_n_last_count]=str[i]; last_str[a]='a'; a++; last_str[a]=' '; a++;} else new_str[i+new_n_last_count]=str[i]; if (str[i] == 'n' && str[i+1] == 'o' && str[i-1] == ' ' && str[i+2] == ' ') {new_str[i+new_n_last_count]=','; new_n_last_count++; new_str[i+new_n_last_count]=str[i]; last_str[a]='n'; a++; last_str[a]='o'; a++; last_str[a]=' '; a++;} else new_str[i+new_n_last_count]=str[i]; } cout << "your string:" << endl; cout << str << endl; cout << "modified string:" << endl; cout << new_str << endl; cout << "number of substrings: " << new_n_last_count+1 << endl; cout << last_str << endl; return 0; }
1/--страниц