Advertisement
Riposati

Untitled

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