Anderson Pozo

Generation

generate functionSun, 25 Jun 2023

Hacer un programa para ingresar una lista de números que finaliza cuando se ingresa un cero, luego informar el máximo y la posición dentro de la lista.

#include <iostream> #include <list> #include <string.h> using namespace std; int main() { string input; list <string> words; while(input != "0"){ cin >> input; words.push_back(input); } int max = 0; list<string>::iterator it; string max_string = ""; for(it = words.begin(); it != words.end(); it++){ if(it->length() > max_string.length()){ max_string = *it; max = it->length(); } } cout << max_string << endl; }

Questions about programming?Chat with your personal AI assistant