Archive for the ‘Problem’ Category

UVA 11483 : Code Creator

Posted: July 19, 2011 in ACM, C++, Problem, UVA
 was one of the splendid problem at least to me. Though it was fairly easy, solving this problem kept me smiling for more then a day. .HAHA.:)
    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #define MX 101
    using namespace std;
    int main()
    {
        int t,kase=1,i,j,m,d=1;
        char st[MX][MX];
        while(cin>>t)
        {
            if(t==0)
            break;
            getchar();
            for(i=0;i<t;i++)
            {
                gets(st[i]);
                if(strlen(st[i])==0)
                    gets(st[i]);
            }
            cout<<"Case "<<kase++<<":"<<endl;
            cout<<"#include<string.h>"<<endl<<"\#include<stdio.h>"<<endl<<"int main()"<<endl<<"{"<<endl;
            for(i=0;i<t;i++)
            {
                cout<<"printf(\"";
                m=strlen(st[i]);
                for(j=0;j<m;j++)
                {
                    switch(st[i][j])
                    {
                        case '"':
                            cout<<'\\'<<st[i][j];
                            break;
                        case '\\':
                            cout<<'\\'<<st[i][j];
                            break;
                        default:
                            cout<<st[i][j];
                            break;
                    }
                }
                cout<<"\\n\");"<<endl;
            }
            cout<<"printf(\"\\n\");"<<endl<<"return 0;"<<endl<<"}"<<endl;
        }
    return 0;
    }