#include #include #include #include std::map vars; // Map from variable names to values char c, s[105], *vs; // vs points to the name of the previous variable char* next() { // This function returns the name of the next variable vs+=2; // Advance to the next variable name return vars[*vs]; // Return the value of the variable } int main(){ int n; scanf("%d ", &n); // Read the number of variables while(n--){ scanf("%c=%s ", &c, s); // Read the variable name and value vars[c] = strdup(s); // Store the variable in the map } fgets(s, 105, stdin); // Read the last line vs = strchr(s, ',') - 1; // Two characters before the first variable name vs[1] = 0; // Remove the comma to terminate the format string here for(char *w = strtok(s, " "); w != NULL; w = strtok(NULL, " ")){ char type = w[strlen(w) - 1]; // The last character of this word, e.g. d for %5d if(w[0] != '%') // If the word is not a format specifier... printf(w); // ...print it directly else if(type == 's') // If the format specifier ends with a s... printf(w, next()); // ...pass it to printf as-is (= as a string) else if(type == 'd') // If the format specifier ends with a d... printf(w, atoi(next())); // ...pass it to printf as an int else // Otherwise (if it ends with a f)... printf(w, atof(next())); // ...pass it to printf as a float putchar(' '); // Put a space after this word } return 0; }