Advertisement
Riposati

Untitled

Jul 29th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.04 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.clear();
  203.     resp2.clear();
  204.  
  205.     resp2 += (numero[1]);
  206.     resp2 += (numero[2]);
  207.  
  208.     string t = resp2;
  209.  
  210.     if(atoi(t.c_str()) <= 20 && atoi(t.c_str()) > 0){
  211.         resp2 = mapaNumeros.find(atoi(t.c_str()))->second;
  212.     }
  213.  
  214.     if(atoi(t.c_str()) >= 21){
  215.         resp2 = retornaDois(resp,t);
  216.     }
  217.  
  218.     resp = retornaTres(resp,numero);
  219.  
  220.     if(resp2!="00"){
  221.         resp+=resp2;
  222.     }
  223.  
  224.     cout<<resp;
  225. }
  226.  
  227. int main()
  228. {
  229.     preencheMapa();
  230.     int valor;
  231.  
  232.     while(scanf("%d",&valor)!=EOF){
  233.  
  234.         resp.clear();
  235.         resp2.clear();
  236.  
  237.         char numero[120000];
  238.         sprintf(numero,"%d",valor);
  239.  
  240.         if(strlen(numero)==1){
  241.             cout<<mapaNumeros.find(valor)->second;
  242.         }
  243.  
  244.         if(strlen(numero)==2 && valor <= 20){
  245.              cout<<mapaNumeros.find(valor)->second;
  246.         }
  247.  
  248.         if(strlen(numero)==2 && valor >= 21){
  249.             resp = retornaDois(resp,numero);
  250.              cout<<resp;
  251.         }
  252.  
  253.         if(strlen(numero)==3){
  254.             paraTresChars(resp,numero);
  255.         }
  256.  
  257.         if(strlen(numero)==4){
  258.  
  259.             char aux[10000];
  260.             aux[0] = numero[1];
  261.             aux[1] = numero[2];
  262.             aux[2] = numero[3];
  263.  
  264.             resp = aux;
  265.  
  266.             if(numero[0]!='1'){
  267.  
  268.                 if(numero[1]!= '0' && numero[2]-'0' == 0 && numero[3]-'0' == 0)
  269.                      cout<<mapaNumeros.find(numero[0]-'0')->second<<" mil e ";
  270.  
  271.                 else
  272.                     cout<<mapaNumeros.find(numero[0]-'0')->second<<" mil ";
  273.             }else{
  274.  
  275.                 if(numero[1]!= '0' && numero[2]-'0' == 0 && numero[3]-'0' == 0)
  276.                     cout<<"mil e ";
  277.  
  278.                 else
  279.                     cout<<"mil ";
  280.             }
  281.  
  282.             paraTresChars(resp,aux);
  283.         }
  284.  
  285.         if(strlen(numero)==5){
  286.  
  287.                 char aux[10000];
  288.                 aux[0] = numero[2];
  289.                 aux[1] = numero[3];
  290.                 aux[2] = numero[4];
  291.  
  292.                 resp = aux;
  293.  
  294.                 char aux2[10000];
  295.  
  296.                 aux2[0] = numero[0];
  297.                 aux2[1] = numero[1];
  298.  
  299.                 int num = atoi(aux2);
  300.  
  301.                 if(num <= 20){
  302.                     cout<<mapaNumeros.find(num)->second<<" mil ";
  303.                 }
  304.  
  305.                 if(num >= 21){
  306.                     resp2 = retornaDois(resp2,aux2);
  307.                     cout<<resp2<<" mil ";
  308.                 }
  309.  
  310.                 if(aux[0]!='0' && aux[1]=='0' && aux[2]=='0'){
  311.                     printf("e ");
  312.                 }
  313.                 paraTresChars(resp,aux);
  314.             }
  315.  
  316.         if(strlen(numero)==6){
  317.                 char aux[10000];
  318.                 aux[0] = numero[3];
  319.                 aux[1] = numero[4];
  320.                 aux[2] = numero[5];
  321.  
  322.                 resp = aux;
  323.  
  324.                 char aux2[10000];
  325.  
  326.                 aux2[0] = numero[0];
  327.                 aux2[1] = numero[1];
  328.                 aux2[2] = numero[2];
  329.  
  330.                 resp2 = aux2;
  331.  
  332.                 paraTresChars(resp2,aux2);
  333.  
  334.                 if(aux[0]!='0' && aux[1]=='0' && aux[2]=='0'){
  335.  
  336.                     printf(" mil e ");
  337.                 }else{
  338.  
  339.                     if(aux[0]=='0' && aux[1]=='0' && aux[2]=='0'){
  340.                         printf(" mil");
  341.                     }else
  342.                         printf(" mil ");
  343.                 }
  344.  
  345.                 paraTresChars(resp,aux);
  346.             }
  347.         printf("\n");
  348.     }
  349.     return 0;
  350. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement