Advertisement
Riposati

Untitled

Jul 29th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <cstdlib>
  4. #include <cstdio>
  5. #include <algorithm>
  6. #include <vector>
  7. #include <string>
  8. #include <string.h>
  9. #include <time.h>
  10.  
  11. using namespace std;
  12.  
  13. map<int,string>mapaNumeros;
  14. string resp;
  15. string resp2;
  16.  
  17. void preencheMapa(){
  18.     mapaNumeros.insert(pair<int,string>(0,"zero"));
  19.     mapaNumeros.insert(pair<int,string>(1,"um"));
  20.     mapaNumeros.insert(pair<int,string>(2,"dois"));
  21.     mapaNumeros.insert(pair<int,string>(3,"tres"));
  22.     mapaNumeros.insert(pair<int,string>(4,"quatro"));
  23.     mapaNumeros.insert(pair<int,string>(5,"cinco"));
  24.     mapaNumeros.insert(pair<int,string>(6,"seis"));
  25.     mapaNumeros.insert(pair<int,string>(7,"sete"));
  26.     mapaNumeros.insert(pair<int,string>(8,"oito"));
  27.     mapaNumeros.insert(pair<int,string>(9,"nove"));
  28.     mapaNumeros.insert(pair<int,string>(10,"dez"));
  29.     mapaNumeros.insert(pair<int,string>(11,"onze"));
  30.     mapaNumeros.insert(pair<int,string>(12,"doze"));
  31.     mapaNumeros.insert(pair<int,string>(13,"treze"));
  32.     mapaNumeros.insert(pair<int,string>(14,"quatorze"));
  33.     mapaNumeros.insert(pair<int,string>(15,"quinze"));
  34.     mapaNumeros.insert(pair<int,string>(16,"dezesseis"));
  35.     mapaNumeros.insert(pair<int,string>(17,"dezessete"));
  36.     mapaNumeros.insert(pair<int,string>(18,"dezoito"));
  37.     mapaNumeros.insert(pair<int,string>(19,"dezenove"));
  38.     mapaNumeros.insert(pair<int,string>(20,"vinte"));
  39.     mapaNumeros.insert(pair<int,string>(30,"trinta"));
  40.     mapaNumeros.insert(pair<int,string>(40,"quarenta"));
  41.     mapaNumeros.insert(pair<int,string>(50,"cinquenta"));
  42.     mapaNumeros.insert(pair<int,string>(60,"sessenta"));
  43.     mapaNumeros.insert(pair<int,string>(70,"setenta"));
  44.     mapaNumeros.insert(pair<int,string>(80,"oitenta"));
  45.     mapaNumeros.insert(pair<int,string>(90,"noventa"));
  46.     mapaNumeros.insert(pair<int,string>(100,"cem"));
  47.     mapaNumeros.insert(pair<int,string>(101,"cento"));
  48.     mapaNumeros.insert(pair<int,string>(200,"duzentos"));
  49.     mapaNumeros.insert(pair<int,string>(300,"trezentos"));
  50.     mapaNumeros.insert(pair<int,string>(400,"quatrocentos"));
  51.     mapaNumeros.insert(pair<int,string>(500,"quinhentos"));
  52.     mapaNumeros.insert(pair<int,string>(600,"seiscentos"));
  53.     mapaNumeros.insert(pair<int,string>(700,"setecentos"));
  54.     mapaNumeros.insert(pair<int,string>(800,"oitocentos"));
  55.     mapaNumeros.insert(pair<int,string>(900,"novecentos"));
  56.     mapaNumeros.insert(pair<int,string>(1000,"mil"));
  57. }
  58.  
  59. string retornaDois(string resp,string numero){
  60.  
  61.         if(numero[0]=='2'){
  62.             resp += mapaNumeros.find(20)->second;
  63.         }
  64.  
  65.         if(numero[0]=='3'){
  66.             resp += mapaNumeros.find(30)->second;
  67.         }
  68.  
  69.         if(numero[0]=='4'){
  70.             resp += mapaNumeros.find(40)->second;
  71.         }
  72.  
  73.         if(numero[0]=='5'){
  74.             resp += mapaNumeros.find(50)->second;
  75.         }
  76.  
  77.         if(numero[0]=='6'){
  78.             resp += mapaNumeros.find(60)->second;
  79.         }
  80.  
  81.         if(numero[0]=='7'){
  82.             resp += mapaNumeros.find(70)->second;
  83.         }
  84.  
  85.         if(numero[0]=='8'){
  86.             resp += mapaNumeros.find(80)->second;
  87.         }
  88.  
  89.         if(numero[0]=='9'){
  90.             resp += mapaNumeros.find(90)->second;
  91.         }
  92.  
  93.         /***** pos 1 */
  94.  
  95.         if(numero[0]!='0' && numero[1]!='0'){
  96.             resp += " e ";
  97.         }
  98.  
  99.         if(numero[1]=='1'){
  100.             resp += mapaNumeros.find(1)->second;
  101.         }
  102.  
  103.         if(numero[1]=='2'){
  104.             resp += mapaNumeros.find(2)->second;
  105.         }
  106.  
  107.         if(numero[1]=='3'){
  108.             resp += mapaNumeros.find(3)->second;
  109.         }
  110.  
  111.         if(numero[1]=='4'){
  112.             resp += mapaNumeros.find(4)->second;
  113.         }
  114.  
  115.         if(numero[1]=='5'){
  116.             resp += mapaNumeros.find(5)->second;
  117.         }
  118.  
  119.         if(numero[1]=='6'){
  120.             resp += mapaNumeros.find(6)->second;
  121.         }
  122.  
  123.         if(numero[1]=='7'){
  124.             resp += mapaNumeros.find(7)->second;
  125.         }
  126.  
  127.         if(numero[1]=='8'){
  128.             resp += mapaNumeros.find(8)->second;
  129.         }
  130.  
  131.         if(numero[1]=='9'){
  132.             resp += mapaNumeros.find(9)->second;
  133.         }
  134.  
  135.         return resp;
  136.     }
  137.  
  138. string retornaTres(string resp,string numero){
  139.  
  140.         if((numero[0]=='1') && (numero[1]=='0' && numero[2]=='0')){
  141.             resp += mapaNumeros.find(100)->second;
  142.         }
  143.  
  144.         if((numero[0]=='1') && (numero[1]!='0' || numero[2]!='0')){
  145.             resp += mapaNumeros.find(101)->second;
  146.         }
  147.  
  148.         if(numero[0]=='2'){
  149.  
  150.             resp += mapaNumeros.find(200)->second;
  151.         }
  152.  
  153.         if(numero[0]=='3'){
  154.  
  155.             resp += mapaNumeros.find(300)->second;
  156.         }
  157.  
  158.         if(numero[0]=='4'){
  159.             resp += mapaNumeros.find(400)->second;
  160.         }
  161.  
  162.         if(numero[0]=='5'){
  163.             resp += mapaNumeros.find(500)->second;
  164.         }
  165.  
  166.         if(numero[0]=='6'){
  167.  
  168.             resp += mapaNumeros.find(600)->second;
  169.         }
  170.  
  171.         if(numero[0]=='7'){
  172.  
  173.             resp += mapaNumeros.find(700)->second;
  174.         }
  175.  
  176.         if(numero[0]=='8'){
  177.  
  178.             resp += mapaNumeros.find(800)->second;
  179.         }
  180.  
  181.         if(numero[0]=='9'){
  182.  
  183.             resp += mapaNumeros.find(900)->second;
  184.         }
  185.  
  186.         if((numero[1]!='0' && numero[2]!='0') ||
  187.            (numero[1]=='0' && numero[2]!='0') ||
  188.            (numero[1]!='0' && numero[2]=='0'))
  189.         {
  190.             if(numero[0]=='0')
  191.                 resp += "e ";
  192.             else{
  193.                 resp += " e ";
  194.             }
  195.         }
  196.  
  197.         return resp;
  198.     }
  199.  
  200. void paraTresChars(string resp,string numero){
  201.  
  202.     resp = "";
  203.     resp2 = "";
  204.  
  205.     resp2 += (numero[1]);
  206.     resp2 += (numero[2]);
  207.  
  208.         char t[numero.size()];
  209.         strcpy(t,resp2.c_str());
  210.  
  211.         if(atoi(t) <= 20 && atoi(t) > 0){
  212.             resp2 = mapaNumeros.find(atoi(t))->second;
  213.         }
  214.  
  215.         if(atoi(t) >= 21){
  216.             resp2 = retornaDois(resp,t);
  217.         }
  218.  
  219.     resp = retornaTres(resp,numero);
  220.  
  221.     if(resp2!="00"){
  222.         resp+=resp2;
  223.     }
  224.  
  225.     printf("%s",resp.c_str());
  226. }
  227.  
  228. int main()
  229. {
  230.     preencheMapa();
  231.     int valor;
  232.  
  233.     while(cin>>valor){
  234.  
  235.         resp.clear();
  236.         resp2.clear();
  237.  
  238.         char numero[120000];
  239.         sprintf(numero,"%d",valor);
  240.  
  241.         if(strlen(numero)==1){
  242.             printf("%s",mapaNumeros.find(valor)->second.c_str());
  243.         }
  244.  
  245.         if(strlen(numero)==2 && valor <= 20){
  246.             printf("%s",mapaNumeros.find(valor)->second.c_str());
  247.         }
  248.  
  249.         if(strlen(numero)==2 && valor >= 21){
  250.             resp = retornaDois(resp,numero);
  251.             printf("%s",resp.c_str());
  252.         }
  253.  
  254.         if(strlen(numero)==3){
  255.             paraTresChars(resp,numero);
  256.         }
  257.  
  258.         if(strlen(numero)==4){
  259.  
  260.             char aux[10000];
  261.             aux[0] = numero[1];
  262.             aux[1] = numero[2];
  263.             aux[2] = numero[3];
  264.  
  265.             resp = aux;
  266.  
  267.             if(numero[0]!='1'){
  268.  
  269.                 if(numero[1]!= '0' && numero[2]-'0' == 0 && numero[3]-'0' == 0)
  270.                     printf("%s mil e ",mapaNumeros.find(numero[0]-'0')->second.c_str());
  271.  
  272.                 else
  273.                     printf("%s mil ",mapaNumeros.find(numero[0]-'0')->second.c_str());
  274.             }else{
  275.  
  276.                 if(numero[1]!= '0' && numero[2]-'0' == 0 && numero[3]-'0' == 0)
  277.                     printf("mil e ",mapaNumeros.find(numero[0]-'0')->second.c_str());
  278.  
  279.                 else
  280.                     printf("mil ",mapaNumeros.find(numero[0]-'0')->second.c_str());
  281.             }
  282.  
  283.             paraTresChars(resp,aux);
  284.         }
  285.  
  286.         if(strlen(numero)==5){
  287.  
  288.                 char aux[10000];
  289.                 aux[0] = numero[2];
  290.                 aux[1] = numero[3];
  291.                 aux[2] = numero[4];
  292.  
  293.                 resp = aux;
  294.  
  295.                 char aux2[10000];
  296.  
  297.                 aux2[0] = numero[0];
  298.                 aux2[1] = numero[1];
  299.  
  300.                 int num = atoi(aux2);
  301.  
  302.                 if(num <= 20){
  303.  
  304.                     if(aux[0]=='0' && aux[1]=='0' && aux[2]=='0'){
  305.                         printf("%s mil",mapaNumeros.find(num)->second.c_str());
  306.                     }else
  307.                         printf("%s mil ",mapaNumeros.find(num)->second.c_str());
  308.                 }
  309.  
  310.                 if(num >= 21){
  311.                     resp2 = retornaDois(resp2,aux2);
  312.  
  313.                     if(aux[0]=='0' && aux[1]=='0' && aux[2]=='0'){
  314.                         printf("%s mil",resp2.c_str());
  315.                     }else
  316.                         printf("%s mil ",resp2.c_str());
  317.                 }
  318.  
  319.                 if(aux[0]!='0' && aux[1]=='0' && aux[2]=='0'){
  320.                     printf("e ");
  321.                 }
  322.                 paraTresChars(resp,aux);
  323.             }
  324.  
  325.         if(strlen(numero)==6){
  326.                 char aux[10000];
  327.                 aux[0] = numero[3];
  328.                 aux[1] = numero[4];
  329.                 aux[2] = numero[5];
  330.  
  331.                 resp = aux;
  332.  
  333.                 char aux2[10000];
  334.  
  335.                 aux2[0] = numero[0];
  336.                 aux2[1] = numero[1];
  337.                 aux2[2] = numero[2];
  338.  
  339.                 resp2 = aux2;
  340.  
  341.                 paraTresChars(resp2,aux2);
  342.  
  343.                 if(aux[0]!='0' && aux[1]=='0' && aux[2]=='0'){
  344.  
  345.                     printf(" mil e ");
  346.                 }else{
  347.  
  348.                     if(aux[0]=='0' && aux[1]=='0' && aux[2]=='0'){
  349.                         printf(" mil");
  350.                     }else
  351.                         printf(" mil ");
  352.                 }
  353.  
  354.                 paraTresChars(resp,aux);
  355.             }
  356.  
  357.         printf("\n");
  358.     }
  359.     return 0;
  360. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement