/* printf finala mindcoding */ #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define LL long long #define PII pair #define PCI pair #define VB vector #define VI vector #define VC vector #define WI vector #define WC vector #define RS resize #define X first #define Y second #define FORN(i,n) for(int i=0;i=b;--i) #define REPEAT do #define UNTIL(x) while((x)) #define IN_FILE "date.in" #define OUT_FILE "date.out" ifstream f(IN_FILE); ofstream g(OUT_FILE); #define scriere cout #define citire cin //variables int n; map vari; string text; VC ord_var; int last_var; //other functions void reading() { citire>> n; FORN(i, n) { string aux; citire>> aux; vari[aux[0]] = aux.substr(2); } getline(f, text); getline(f, text); f.close(); } void solving() { int start = text.find(','); string aux = text.substr(start+1)+','; FOR(i, 0, aux.length()) { i = 0; ord_var.push_back(aux[0]); aux = aux.substr(2); i = 0; } text = text.substr(0,start); FORN(i, text.length()) { if (text[i] == '%') { if (i != 0) { if (text[i - 1] != ' ') { continue; } } if (text[i + 1] == 's') { text = text.substr(0, i) + vari[ord_var[last_var]] + text.substr(i + 2); ++last_var; } else if (text[i + 1] == '.') { int pos = i + 2; int lenght = 0; while (text[pos] > 47 && text[pos] < 58) { lenght *= 10; lenght += text[pos] - 48; ++pos; } string value = vari[ord_var[last_var]]; ++last_var;; int k=0; for (k = 0; true; ++k) { if (value[k] == '.') { break; } } if (k + 1 + lenght < value.length()) { if (value[k + 1 + lenght ]>52) { ++value[k + lenght]; } } string ans = value.substr(0, k + 1+lenght); text = text.substr(0,i)+ans+text.substr(pos+1); } else if (text[i + 2] == 'd' && text[i + 1] > 47 && text[i + 1] < 58) { string ans = ""; ans += vari[ord_var[last_var]]; int repe = text[i + 1] - 48-ans.length(); FORN(i, repe) { ans = ' '+ans; } ++last_var; text = text.substr(0,i)+ans+ text.substr(i+3); } } } } void write_data() { scriere<< text; } int main() { reading(); solving(); write_data(); }