// *********** Функция main *********************** // #include "stdafx.h" #include <iostream> #include <conio.h> #include <iomanip> #include <time.h> using std::cout; using std::cin; using std::endl; using std::setw; char* FunctionsBigSmallWord(char *cArrayTextChange, int iSizeArray, int *iArraySizeResultBigWord); char* FunctionsSmallWord(char *cArrayTextChange, int iSizeArray, int *iArraySizeResultSmallWord); void FunctionOutput(char *cArrayText); int _tmain(int argc, _TCHAR* argv[]) { //"When considering the first issue of the scientific philosophy can be seen that throughout its history, philosophy - one of the sources of human knowledge."; char cArrayText[] = "Immanent approach involves attitude if";//Source text int iArraySize = sizeof(cArrayText)/sizeof(char), iArraySizeResultBigWord = 0, iArraySizeResultSmallWord = 0; char *cResultBigWord = FunctionsBigSmallWord(cArrayText, iArraySize, &iArraySizeResultBigWord); char *cResultSmallWord = FunctionsSmallWord(cArrayText, iArraySize, &iArraySizeResultSmallWord); ////////////////////////////////////////////////// /* *Creating text for the withdrawal of the smallest owl in the text */ char cArrayResultSmallest[] = "The smallest word in the text - "; int iAllSizeSmallest = iArraySizeResultSmallWord + sizeof(cArrayResultSmallest)/sizeof(char); char *pArrResultTextSmallest = new char[iAllSizeSmallest];//Allocate memory for result text bool bFlagsSmallest = false; for(int i = 0, iCuntenter = 0; i < iAllSizeSmallest; ++i) { if(bFlagsSmallest == false) { *(pArrResultTextSmallest + i) = *(cArrayResultSmallest + i); } if(*(pArrResultTextSmallest + i) == 0)//Add a space instead of "0" at the end of the first row { *(pArrResultTextSmallest + i) = ' '; bFlagsSmallest = true; } if(bFlagsSmallest) { *(pArrResultTextSmallest + i) = *(cResultSmallWord + iCuntenter); ++iCuntenter; } } *(pArrResultTextSmallest + iAllSizeSmallest-1) = 0; //////////////////////////////////////////////////////// ////////////////////////////////////////////////// /* *Creating text for the withdrawal of the biggest words in the text */ char cArrayResultBiggest[] = "The biggest word in the text - "; int iAllSizeBiggest = iArraySizeResultBigWord + sizeof(cArrayResultBiggest)/sizeof(char); char *pArrResultTextBiggest = new char[iAllSizeBiggest];//Allocate memory for result text bool bFlagsBiggest = false; for(int i = 0, iCuntenter = 0; i < iAllSizeBiggest; ++i) { if(bFlagsBiggest == false) { *(pArrResultTextBiggest + i) = *(cArrayResultBiggest + i); } if(*(pArrResultTextBiggest + i) == 0)//Add a space instead of "0" at the end of the first row { *(pArrResultTextBiggest + i) = ' '; bFlagsBiggest = true; } if(bFlagsBiggest) { *(pArrResultTextBiggest + i) = *(cResultBigWord + iCuntenter); ++iCuntenter; } } *(pArrResultTextBiggest + iAllSizeBiggest-1) = 0; //////////////////////////////////////////////////////// std::cout<<"Source text: "<<std::endl; std::cout<<std::endl; FunctionOutput(cArrayText); std::cout<<"======================================================"<<std::endl; std::cout<<std::endl; FunctionOutput(pArrResultTextSmallest); std::cout<<std::endl; std::cout<<"======================================================"<<std::endl; std::cout<<std::endl; FunctionOutput(pArrResultTextBiggest); std::cout<<std::endl; delete [] pArrResultTextSmallest; delete [] pArrResultTextBiggest; delete [] cResultBigWord; delete [] cResultSmallWord; return 0; }
Работа со строками (самое большое самое маленькое слово в тексте)
Сообщений 1 страница 5 из 5
Поделиться131-03-2011 14:46:35
Поделиться231-03-2011 14:48:11
//========================================================================================= /* *Function searches for the greatest word */ //========================================================================================= char* FunctionsBigSmallWord(char *cArrayTextChange, int iSizeArray, int *iArraySizeResultBigWord) { int iBigWordMem = 0, iBigWordMemIndex = 0; bool bFlagsIndex = true; for(int i = 0, iBigWordCount = 0, iBigWordIndex = 0; i < iSizeArray; ++i) { if(*(cArrayTextChange + i) != ' ' && *(cArrayTextChange + i) != 0 ) { if(bFlagsIndex) { iBigWordIndex = i;//Know the starting index of the biggest words } ++iBigWordCount;//We believe the characters in the word bFlagsIndex = false; } else { if(iBigWordMem < iBigWordCount) { /* *Save the biggest word, and its index */ iBigWordMemIndex = iBigWordIndex; iBigWordMem = iBigWordCount; } bFlagsIndex = true; iBigWordCount = 0; } } ++iBigWordMem;//Add a place to "0" *(iArraySizeResultBigWord) = iBigWordMem;//transfer size of the array in the main function char *pArrBigWord = new char[iBigWordMem];//Allocate memory for word /* *Copy the word from the text */ for(int i = 0; i < iBigWordMem; ++i) { *(pArrBigWord + i) = *(cArrayTextChange + (iBigWordMemIndex + i)); } *(pArrBigWord + (iBigWordMem - 1)) = 0; return pArrBigWord; } //========================================================================================= /* *Function looks for the smallest word */ //========================================================================================= char* FunctionsSmallWord(char *cArrayTextChange, int iSizeArray, int *iArraySizeResultSmallWord) { int iSmallWordMem = 100, iSmallWordMemIndex = 0; bool bFlagsIndex = true; for(int i = 0, iSmallWordCount = 0, iSmallWordIndex = 0; i < iSizeArray; ++i) { if(*(cArrayTextChange + i) != ' ' && *(cArrayTextChange + i) != 0 ) { if(bFlagsIndex) { iSmallWordIndex = i;//Know the starting index of the smallest words } ++iSmallWordCount;//We believe the characters in the word bFlagsIndex = false; } else { /* *Saving the first small words */ if(iSmallWordMem > iSmallWordCount) { /* *Save the smallest word, and its index */ iSmallWordMemIndex = iSmallWordIndex; iSmallWordMem = iSmallWordCount; } bFlagsIndex = true; iSmallWordCount = 0; } } ++iSmallWordMem;//Add a place to "0" *(iArraySizeResultSmallWord) = iSmallWordMem;//transfer size of the array in the main function char *pArrSmallWord = new char[iSmallWordMem];//Allocate memory for word /* *Copy the word from the text */ for(int i = 0; i < iSmallWordMem; ++i) { *(pArrSmallWord + i) = *(cArrayTextChange + (iSmallWordMemIndex + i)); } *(pArrSmallWord + (iSmallWordMem - 1)) = 0; return pArrSmallWord; }
Поделиться331-03-2011 14:48:55
//========================================================================================= /* *Output function of the array */ //========================================================================================= void FunctionOutput(char *cArrayText) { for(int i = 0;*(cArrayText + i) != 0; ++i) { cout<<*(cArrayText + i); } cout<<endl; }
Поделиться431-03-2011 14:54:14
копировать всё по порядку
Поделиться514-07-2023 16:51:47
This231.1CHAPTESTIsaaAutrAlarWendDeclIlyaCognFiskClubSimpBoilMarcStepDeclXVIIHistZoneLove
AssaTescKurtTescJorgWindPantJeweXVIIDancAhavGonnHadaKeenMangPenhEmilBiocNiveJamePeteXVII
CariFrotPhilRobeTranBowmTowaStriRomaMariAMIEGilbmattEtudBennDoroRobePatrMoorgunmStevNiki
BabaDmitJupeNaviCallJaanCityJillwwwiStevRobeElsaWindNokiCoreElasSoftNBRBAltfEverpacaArts
FuxiJeanXboxFuxidiamAnneArtsFourMiyoPhilBlueSennVitaUnchXVIIStefWindJunkClifTomaJaroDucc
LogiLibeSticValiWildJeweJeanDHChInduGusuTERPBoscNVMTAdveEducBookDaniDiscTropSeveGDeBSQui
PierMystSTARLNSFCampFreeMidiEditPlayAngeMultHellwwwmAbanMicrWindProfZelmhappPacoBritFant
DeadShakBestThisLawiMidnChimNettXenoStevProsCharChriAcadStefErnsMartMariBariMcKiResuSerg
IvanNiveGotzMedaNickBrucMahlJohnKlauMadoPhilWindSidePavaSodoBesiChriBattStevMemeVampThom
JeweRoalNyloSusaDragAstrGeldInduInduInduWindYannRounSilvNaraTracLaneTrinThomDandAlerRake
tuchkasShakEliz