Advertisement
Riposati

Untitled

Jul 30th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.66 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. //    int y = 900000;
  232.  
  233.     //while(y <= 999999){
  234.     while(scanf("%d",&valor)!=EOF){
  235.  
  236.         resp.clear();
  237.         resp2.clear();
  238.  
  239. //        valor = y;
  240.  
  241.         char numero[120000];
  242.         sprintf(numero,"%d",valor);
  243.  
  244.         if(strlen(numero)==1){
  245.             cout<<mapaNumeros.find(valor)->second;
  246.         }
  247.  
  248.         if(strlen(numero)==2 && valor <= 20){
  249.              cout<<mapaNumeros.find(valor)->second;
  250.         }
  251.  
  252.         if(strlen(numero)==2 && valor >= 21){
  253.             resp = retornaDois(resp,numero);
  254.              cout<<resp;
  255.         }
  256.  
  257.         if(strlen(numero)==3){
  258.             paraTresChars(resp,numero);
  259.         }
  260.  
  261.         if(strlen(numero)==4){
  262.  
  263.             char aux[10000];
  264.             aux[0] = numero[1];
  265.             aux[1] = numero[2];
  266.             aux[2] = numero[3];
  267.  
  268.             resp = aux;
  269.  
  270.             if(numero[0]!='1'){
  271.  
  272.                 if(numero[1]!= '0' && numero[2]-'0' == 0 && numero[3]-'0' == 0){
  273.                      cout<<mapaNumeros.find(numero[0]-'0')->second<<" mil e ";
  274.                      paraTresChars(resp,aux);
  275.  
  276.                 }else{
  277.                     cout<<mapaNumeros.find(numero[0]-'0')->second<<" mil ";
  278.                     paraTresChars(resp,aux);
  279.                 }
  280.             }else{
  281.  
  282.                 if(numero[1]!= '0' && numero[2]-'0' == 0 && numero[3]-'0' == 0){
  283.                     cout<<"mil e ";
  284.                     paraTresChars(resp,aux);
  285.                 }
  286.  
  287.                 else{
  288.                     cout<<"mil ";
  289.                     paraTresChars(resp,aux);
  290.                 }
  291.             }
  292.  
  293.  
  294.         }
  295.  
  296.         if(strlen(numero)==5){
  297.  
  298.                 char aux[10000];
  299.                 aux[0] = numero[2];
  300.                 aux[1] = numero[3];
  301.                 aux[2] = numero[4];
  302.  
  303.                 resp = aux;
  304.  
  305.                 char aux2[10000];
  306.  
  307.                 aux2[0] = numero[0];
  308.                 aux2[1] = numero[1];
  309.  
  310.                 int num = atoi(aux2);
  311.  
  312.                 if(num <= 20){
  313.                     cout<<mapaNumeros.find(num)->second<<" mil ";
  314.  
  315.                     if(aux[0]!='0' && aux[1]=='0' && aux[2]=='0'){
  316.                         printf("e ");
  317.                     }
  318.  
  319.                     paraTresChars(resp,aux);
  320.                 }
  321.  
  322.                 if(num >= 21){
  323.                     resp2 = retornaDois(resp2,aux2);
  324.                     cout<<resp2<<" mil ";
  325.  
  326.                     if(aux[0]!='0' && aux[1]=='0' && aux[2]=='0'){
  327.                         printf("e ");
  328.                     }
  329.  
  330.                     paraTresChars(resp,aux);
  331.                 }
  332.             }
  333.  
  334.         if(strlen(numero)==6){
  335.                 char aux[10000];
  336.                 aux[0] = numero[3];
  337.                 aux[1] = numero[4];
  338.                 aux[2] = numero[5];
  339.  
  340.                 resp = aux;
  341.  
  342.                 char aux2[10000];
  343.  
  344.                 aux2[0] = numero[0];
  345.                 aux2[1] = numero[1];
  346.                 aux2[2] = numero[2];
  347.  
  348.                 resp2 = aux2;
  349.  
  350.                 paraTresChars(resp2,aux2);
  351.  
  352.                 if(aux[0]!='0' && aux[1]=='0' && aux[2]=='0'){
  353.  
  354.                     printf(" mil e ");
  355.  
  356.                     paraTresChars(resp,aux);
  357.                 }else{
  358.  
  359.                     if(aux[0]=='0' && aux[1]=='0' && aux[2]=='0'){
  360.                         printf(" mil");
  361.  
  362.                         paraTresChars(resp,aux);
  363.                     }else{
  364.                         printf(" mil ");
  365.                         paraTresChars(resp,aux);
  366.                     }
  367.                 }
  368.  
  369.  
  370.             }
  371. //        y++;
  372.  
  373.         printf("\n");
  374.     }
  375.     return 0;
  376. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement