Помогите пожалуйста как упорядочить номера маршрутов по возрастанию?? вот мой код #include #include #include #include using std::cin; using std::cout; struct MARSH { char BEGST[ 50 ]; //initial point char TERM [ 50 ];...
Помогите пожалуйста
как упорядочить номера маршрутов по возрастанию??
вот мой код
#include
#include
#include
#include
using std::cin;
using std::cout;
struct MARSH
{
char BEGST[ 50 ]; //initial point
char TERM [ 50 ]; //end point
unsigned int NUMER; //number of the route
};
int main( void )
{
const short size = 9; //size of array
MARSH array[ size ]; //array of our structure
//filling of the array
for( int i=1; i {
cout « "\nVvedite nazvanie nachalnogo punkta marshruta: "; cin » array[ i ].BEGST;
cout « "\nVvedite nazvanie konechnogo punkta marshruta: "; cin » array[ i ].TERM;
cout « "\nVvedite nomer marshruta: "; cin » array[ i ].NUMER;
cout « "\n\n";
}
//printing of the information
for( int i=1; i {
cout « "array[ " « i « " ].Nazvanie nachalnogo punkta = " « array[ i ].BEGST;
cout « "\narray[ " « i « " ]. Nazvanie konechnogo punkta = " « array[ i ].TERM;
cout « "\narray[ " « i « " ].Nomer marshruta = " « array[ i ].NUMER;
cout « "\n\n";
}
//reception of number of the route (by the task)
unsigned int toFind;
cout « "Enter number of the route to find: "; cin » toFind;
for( int i=1; i {
if( toFind == array[ i ].NUMER)
{
cout « "\nNazvanie nachalnogo punkta = " « array[ i ].BEGST;
cout « "\nNazvanie konechnogo punkta= " « array[ i ].TERM;
cout « "\nNomer marshruta = " « array[ i ].NUMER;
if( toFind != array[ i ].NUMER)
cout « "net!!!";
}
}
return 0;
}
Ответ(ы) на вопрос:
Создаешь цикл for , который записывает номера array[ i ].NUMER; в отдельный массив . Затем массив прогоняешь массив циклом for и ищешь максимум (не забудь добавить переменную-счетчик что б он выводил не первый максимум, а только тогда, когда пройдет весь массив). Затем выведенное число заменяешь на 0 . Тебе понадобится еще одна переменная-счетчик, что бы после того как он выведет тебе все номера, он не начал выводить нули.
Костыльно конечно , но этот способ работает. Успехов!
Не нашли ответ?
Похожие вопросы