// less6_bad_road.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <conio.h> #include <iomanip> #include <time.h> void FunctionFillRandomNumbers(int *iArray, int iArraySize, int iRangeRandNumbers); void FunctionViewArray(int *iArray, int iArraySize); int* FunctionCountingTheBrokenParts(int *iArray, int iArraySize, bool bDrawStatistic); int _tmain(int argc, _TCHAR* argv[]) { const int iARRAY_SIZE = 100; int iArrayRoad[iARRAY_SIZE] = {0}; int *iResult; FunctionFillRandomNumbers(iArrayRoad, (sizeof(iArrayRoad)/sizeof(int)), 21); FunctionViewArray(iArrayRoad,(sizeof(iArrayRoad)/sizeof(int))); std::cout<<"======================================="<<std::endl; iResult = FunctionCountingTheBrokenParts(iArrayRoad,(sizeof(iArrayRoad)/sizeof(int)), true); std::cout<<"======================================="<<std::endl; std::cout<<*(iResult)*100/iARRAY_SIZE<<'%'<<" roads in good condition "<<std::endl; std::cout<<*(iResult+1)*100/iARRAY_SIZE<<'%'<<" roads in need of repair "<<std::endl; return 0; } //================================================================ /* *The function fills the array with random numbers */ //================================================================ void FunctionFillRandomNumbers(int *iArray, int iArraySize, int iRangeRandNumbers) { srand((unsigned int)time(NULL)); for(int i = 0; i < iArraySize; ++i) { *(iArray + i) = rand()%iRangeRandNumbers; } } //================================================================ /* *Displays the contents of the array */ //================================================================ void FunctionViewArray(int *iArray, int iArraySize) { for(int i = 0, counter = 1; i < iArraySize; ++i, ++counter) { std::cout<<std::setw(3)<<*(iArray + i)<<' '; if(counter%10 == 0) { std::cout<<std::endl; } } std::cout<<std::endl; } //================================================================ /* *Processing function of the array of data containing information about the damaged sections of road */ //================================================================ int* FunctionCountingTheBrokenParts(int *iArray, int iArraySize, bool bDrawStatistic) { static int iArrayStatistic[2] = {0}; int iBadSector = 10; bool bFlags = true; for(int i = 0, iCauntVeryBad = 0; i < iArraySize; ++i) { /* *Select the symbol to draw the bad parts */ if(bDrawStatistic) //Whether to draw the statistics { if(*(iArray + i) >= iBadSector && *(iArray + (i+1)) >= iBadSector && *(iArray + (i+2)) >= iBadSector) { bFlags = false; iCauntVeryBad = 3; } if(iCauntVeryBad == 0) { bFlags = true; } } if(*(iArray + i) < iBadSector) { if(bDrawStatistic) { for(int j = 0; j <= *(iArray + i); ++j) { if(*(iArray + i)) { std::cout<<'*'; } } std::cout<<std::endl; } /* *Save the good parts of the road */ ++*(iArrayStatistic); } else { if(bDrawStatistic) { for(int j = 0; j <= *(iArray + i); ++j) { if(bFlags) { std::cout<<'#'; } else { std::cout<<'$'; } } --iCauntVeryBad; std::cout<<std::endl; } /* *Keeping the bad stretches of road */ ++*(iArrayStatistic+1); } } std::cout<<std::endl; return iArrayStatistic; }
Работа с массивами (рисуем ряды * , # и $) Задача про дорогу.
Сообщений 1 страница 2 из 2
Поделиться122-03-2011 00:47:15
Поделиться214-07-2023 16:06:25
Agat216.2CHAPaddiLouiMeinCafeApplCharichiRobeCantMickwwwnBriaEverTomaElizAndrInsoPoliVisi
TescAlphAlekOmegHermLacaAhavFinaEdgaDiamDoctBallFromHurrPureBoogFranStepTaftMargXVIINint
KreoMythSlimAdriwwwbBattAlbeCotoWindScotlighBlueGardBodeBehiSinkAvenMariXVIIblacCharRoge
AlleAlteYourCollPoweXVIIDiscEltoWindPhilCallJorgRighJameThieSideThisArtsViraMorrHeadAAGQ
ErleNikiHollArtsArtsZebrArtsArtsMartXVIIJohnGerdAlonJameHerbJoycJuliliveLessPiteSonyClin
SwarSamsFollShitWaggSteeMadeMHohCMOSHANDRagoNardArisAmazCrasBookBeflDelpUnitPolaAdriSwar
ProfProlAVTOmeloNettSmooGerbVictBeadEnglBlanMitsWindWindwwwnmpegWinxDeLoMakiMexxKittreal
specStarImmaGammNeveErotDimeOZONEaglWindDidiJeweKarlFranCharultiWindDolbLeonJockRighLiry
EnhaMcDoArunConsJacqDeepDamnLarrSpeeLeslApplXVIIMuddRichLewiPinnPoolDirtwwwrmomeTherMayb
BurnMichWaldElviAmazAnnaAudiCMOSCMOSCMOSDolpMoonChapHenrRockEmotUriaonliFiatJeffMaitCoda
tuchkasJoseAstr