Advertisement
tomasaccini

Untitled

Jul 23rd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <list>
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. size_t hexa_to_decimal(char c) {
  7.     if (c >= '0' && c <= '9')
  8.         return (size_t)(c-'0');
  9.     else
  10.         return (size_t)(c-'A' + 10);
  11. }
  12.  
  13. std::istream& operator >> (std::istream& i, std::list<std::string>& l) {
  14.     std::cout << "Ingrese el numero de elementos a cargar en formato hexa: ";
  15.     char aux[100];
  16.     i >> aux;
  17.     size_t len_aux = strlen(aux);
  18.     size_t mult = 1;
  19.     size_t cantidad = 0;
  20.     for (size_t j = 0; j < len_aux; ++j) {
  21.         cantidad += hexa_to_decimal(aux[j]) * mult;
  22.         mult *= 16;
  23.     }
  24.     for (size_t j = 0; j < cantidad; ++j) {
  25.         i >> aux;
  26.         std::string aux_string(aux);
  27.         l.push_back(aux_string);
  28.     }
  29.     return i;
  30. }
  31.  
  32. int main() {
  33.     std::list<std::string> l;
  34.     std::cin >> l;
  35.  
  36.     std::list<std::string>::iterator it = l.begin();
  37.     while (it != l.end()) {
  38.         std::cout << *it << std::endl;
  39.         ++it;
  40.     }
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement