Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // numeros astronomicos
- #include <fstream>
- #include "pilas_con_listas.h"
- using namespace std;
- stack& leer_numero (string nombre)
- {
- stack s;
- int a;
- ifstream input (nombre);
- if (not input.is_open())
- {
- cout << "No se encontro el archivo." << endl;
- return s;
- }
- while (input >> a)
- push(s,a);
- return s;
- }
- stack sumar_numeros (stack& a, stack& b)
- {
- int x, y, suma=0, resto=0; stack s;
- while (not is_stack_empty(a) and not is_stack_empty(b))
- {
- pop(a,x);
- pop(b,y);
- suma = x+y+resto;
- resto=0;
- if (suma>9)
- {
- suma = suma%10;
- resto++;
- }
- push(s, suma);
- suma=0;
- }
- while (not is_stack_empty(a))
- {
- pop(a,x);
- suma = x + resto;
- resto = 0;
- if (suma>9)
- {
- suma = suma%10;
- resto++;
- }
- push(s, suma);
- suma=0;
- }
- while (not is_stack_empty(b))
- {
- pop(b,x);
- suma = x + resto;
- resto = 0;
- if (suma>9)
- {
- suma = suma%10;
- resto++;
- }
- push(s, suma);
- suma=0;
- }
- if (resto != 0)
- push (s,1);
- return s;
- }
- int main()
- {
- stack a, b, c; string nombre; int d;
- nombre = "archivo1.txt";
- a = leer_numero(nombre);
- nombre = "archivo2.txt";
- b = leer_numero(nombre);
- c = sumar_numeros(a,b);
- vaciar_stack(c);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement