Submission #308780

# Submission time Handle Problem Language Result Execution time Memory
308780 2020-10-01T23:25:03 Z Doda Mobitel (COCI14_mobitel) C++17
50 / 50
1 ms 384 KB
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define pb push_back
#define fr(n) for (int i = 0; i<n;i++)

typedef long long ll;
using namespace std;

ll pot (ll q, ll w){
    ll qw = 1;
    for (ll i = 0; i<w; i++)
        qw*= q;
    return qw;
}

int v[10];
string rijec,rj;
map <char,string> slova;

int main () {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);

for (int i = 1; i<=9;i++){
    int a;
    cin >> a;
    v[i] = a;
}

cin >> rijec;

slova['a']="2";
slova['b']="22";
slova['c']="222";
slova['d']="3";
slova['e']="33";
slova['f']="333";
slova['g']="4";
slova['h']="44";
slova['i']="444";
slova['j']="5";
slova['k']="55";
slova['l']="555";
slova['m']="6";
slova['n']="66";
slova['o']="666";
slova['p']="7";
slova['q']="77";
slova['r']="777";
slova['s']="7777";
slova['t']="8";
slova['u']="88";
slova['v']="888";
slova['w']="9";
slova['x']="99";
slova['y']="999";
slova['z']="9999";

fr(rijec.size()){
    char a = rijec[i];
    string s = slova[a];
    int l = s.size();
    char br= s[0];
    int broj = int(br)-int('0');
    int nbr;
    for (int j = 1;j<10;j++)
        if (v[j] == broj)
            nbr = j;
    // int nbr = v[broj];
    nbr += int('0');
    br = static_cast<char>(nbr);
    int len = rj.size();
    if (rj[len-1] == br)
        rj+='#';
    for (int j = 0;j<l;j++)
        rj+=br;
}


cout << rj;


return 0;
}

Compilation message

mobitel.cpp: In function 'int main()':
mobitel.cpp:11:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 | #define fr(n) for (int i = 0; i<n;i++)
      |                               ~^~~~~~~
   12 | 
      |                                 
   13 | typedef long long ll;
      | ~~~~~~~~~~~~~~~~~~~~~           
   14 | using namespace std;
      | ~~~~~~~~~~~~~~~~~~~~            
   15 | 
      |                                 
   16 | ll pot (ll q, ll w){
      | ~~~~~~~~~~~~~~~~~~~~            
   17 |     ll qw = 1;
      |     ~~~~~~~~~~                  
   18 |     for (ll i = 0; i<w; i++)
      |     ~~~~~~~~~~~~~~~~~~~~~~~~    
   19 |         qw*= q;
      |         ~~~~~~~                 
   20 |     return qw;
      |     ~~~~~~~~~~                  
   21 | }
      | ~                               
   22 | 
      |                                 
   23 | int v[10];
      | ~~~~~~~~~~                      
   24 | string rijec,rj;
      | ~~~~~~~~~~~~~~~~                
   25 | map <char,string> slova;
      | ~~~~~~~~~~~~~~~~~~~~~~~~        
   26 | 
      |                                 
   27 | int main () {
      | ~~~~~~~~~~~~~                   
   28 | ios::sync_with_stdio(0);
      | ~~~~~~~~~~~~~~~~~~~~~~~~        
   29 | cin.tie(0); cout.tie(0);
      | ~~~~~~~~~~~~~~~~~~~~~~~~        
   30 | 
      |                                 
   31 | for (int i = 1; i<=9;i++){
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~      
   32 |     int a;
      |     ~~~~~~                      
   33 |     cin >> a;
      |     ~~~~~~~~~                   
   34 |     v[i] = a;
      |     ~~~~~~~~~                   
   35 | }
      | ~                               
   36 | 
      |                                 
   37 | cin >> rijec;
      | ~~~~~~~~~~~~~                   
   38 | 
      |                                 
   39 | slova['a']="2";
      | ~~~~~~~~~~~~~~~                 
   40 | slova['b']="22";
      | ~~~~~~~~~~~~~~~~                
   41 | slova['c']="222";
      | ~~~~~~~~~~~~~~~~~               
   42 | slova['d']="3";
      | ~~~~~~~~~~~~~~~                 
   43 | slova['e']="33";
      | ~~~~~~~~~~~~~~~~                
   44 | slova['f']="333";
      | ~~~~~~~~~~~~~~~~~               
   45 | slova['g']="4";
      | ~~~~~~~~~~~~~~~                 
   46 | slova['h']="44";
      | ~~~~~~~~~~~~~~~~                
   47 | slova['i']="444";
      | ~~~~~~~~~~~~~~~~~               
   48 | slova['j']="5";
      | ~~~~~~~~~~~~~~~                 
   49 | slova['k']="55";
      | ~~~~~~~~~~~~~~~~                
   50 | slova['l']="555";
      | ~~~~~~~~~~~~~~~~~               
   51 | slova['m']="6";
      | ~~~~~~~~~~~~~~~                 
   52 | slova['n']="66";
      | ~~~~~~~~~~~~~~~~                
   53 | slova['o']="666";
      | ~~~~~~~~~~~~~~~~~               
   54 | slova['p']="7";
      | ~~~~~~~~~~~~~~~                 
   55 | slova['q']="77";
      | ~~~~~~~~~~~~~~~~                
   56 | slova['r']="777";
      | ~~~~~~~~~~~~~~~~~               
   57 | slova['s']="7777";
      | ~~~~~~~~~~~~~~~~~~              
   58 | slova['t']="8";
      | ~~~~~~~~~~~~~~~                 
   59 | slova['u']="88";
      | ~~~~~~~~~~~~~~~~                
   60 | slova['v']="888";
      | ~~~~~~~~~~~~~~~~~               
   61 | slova['w']="9";
      | ~~~~~~~~~~~~~~~                 
   62 | slova['x']="99";
      | ~~~~~~~~~~~~~~~~                
   63 | slova['y']="999";
      | ~~~~~~~~~~~~~~~~~               
   64 | slova['z']="9999";
      | ~~~~~~~~~~~~~~~~~~              
   65 | 
      |                                 
   66 | fr(rijec.size()){
      | ~~~~~~~~~~~~~~~                 
mobitel.cpp:66:1: note: in expansion of macro 'fr'
   66 | fr(rijec.size()){
      | ^~
mobitel.cpp:77:9: warning: 'nbr' may be used uninitialized in this function [-Wmaybe-uninitialized]
   77 |     nbr += int('0');
      |     ~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct