#include <iostream>
#include <string>

using namespace std;

class Printf {
public:
   int run(int argc, char ** argv) {
      if(argc == 1) return 1;
      string fmt = argv[1];
      size_t j = 2;
      for(size_t i = 0; i < fmt.size(); i++) {
         if(fmt[i] == '\\') {
            i++;
            if(i < fmt.size()) {
               switch(fmt[i]) {
               case 'n':
               cout << '\n';
               break;
               case 'r':
               cout << '\r';
               break;
               case 't':
               cout << '\t';
               break;
               case '\\':
               cout << '\\';
               break;
               case '\"':
               cout << '\"';
               break;
               }
            }
         }
         else if(fmt[i] == '%') {
            i++;
            if(i < fmt.size()) {
               switch(fmt[i]) {
               case 'd':
               cout << atoi(argv[j]);
               j++;
               break;

               case 's':
               cout << argv[j];
               j++;
               break;

               case 'f':
               cout << atof(argv[j]);
               j++;
               break;

               case 'g':
               cout << atof(argv[j]);
               j++;
               break;

               case 'x':
               cout << hex << atoi(argv[j]) << dec;
               j++;
               break;

               case 'c':
               cout << (char)atoi(argv[j]);
               j++;
               break;

               case '%':
               cout << '%';
               i++;
               break;
               }
               if(j >= argc) {
                  break;
               }
            }
         }
         else {
            cout << fmt[i];
         }
      }
      cout << flush;
      return 0;
   }
};

#ifdef NO_MAIN
extern "C" {
extern int printf_main(int argc, char ** argv);
}
int printf_main(int argc, char ** argv)
#else
int main(int argc, char ** argv)
#endif
{
   Printf printf_obj;
   int rc = printf_obj.run(argc,argv);
   return rc;
}
