24h購物| | PChome| 登入
2012-03-30 15:04:47| 人氣2,388| 回應0 | 上一篇 | 下一篇

[UVA] 11483 - Code Creator

推薦 0 收藏 0 轉貼0 訂閱站台

C

Code Creator

 

 

With increased popularity of programming competitions, there are so many online judges where contestants can practice. Usually, most of these sites allow users to submit solutions to problems and if they are accepted, the users total number of solved is increased. To increase competition among users, these sites maintain a ranking of users based on the total number of solves. Unfortunately, this at times has introduced unhealthy competition among some users. A lot of the problems at these sites are collected from external sites, and the online judge uses data file directly from these external sites. This means, for certain problem, one is only required to submit the output file to get a problem accepted, without solving the problem at all. Just out of curiosity, you try to investigate how many of these problems are actually using judge data from the external site. To accelerate your investigation, you want to automate the process of creating codes that will submit judge data only. In this problem, you are required to make such a code generator.

Input

Each case of input starts with a positive integer N<100. N lines follow each containing at least 1 and at most 100 characters. The Input characters will consist of alphanumeric, spaces, backslash and quotation only. The last case is followed by a value of 0 for N.

Output

Each case of output will start with a line containing the case number in the format Case x: where x is the case number. The next few lines will be a C code which when compiled and run will generate the input given for that case. Since there are so many ways to write a program that will generate the same output, for this problem we will restrict ourselves to the following format.

#include<string.h>
#include<stdio.h>
int main()
{
<case specific lines>
printf(“\n”);
return 0;
}

 

<case specific lines> will contain the same number of lines as N for that case, each formatted as: printf(“<line>\n”); where <line> is the input value entered for that corresponding line. Note that, the two characters and \ must be escaped by a \ in order to be displayed by printf . The sample input/output will clarify further.

In case you are curious, why there is a printf(“\n”); before the return 0; , it’s there to get this code presentation error so that it’s not counted as accepted. You don’t want to increase your number that way, do you?

Sample Input

2

“I like to solve”
I do not like to code
1
yeah accepted
0

Sample Output

Case 1:
#include<string.h>
#include<stdio.h>
int main()
{
printf(“\”I like to solve\”\n”);
printf(“I do not like to code\n”);
printf(“\n”);
return 0;
}
Case 2:
#include<string.h>
#include<stdio.h>
int main()
{
printf(“yeah accepted\n”);
printf(“\n”);
return 0;
}


只需要注意 '\\' 跟 '\"' 即可

#include<stdio.h>
int main() {
    int n, Case = 0, i, j;
    char str[1002];
    while(scanf("%d", &n) == 1 && n) {
        getchar();
        printf("Case %d:\n", ++Case);
        puts("#include<string.h>\n#include<stdio.h>\nint main()\n{");
        while(n--) {
            gets(str);
            printf("printf(\"");
            for(i = 0; str[i]; i++) {
                if(str[i] == '\\' || str[i] == '\"')
                    printf("\\");
                printf("%c", str[i]);
            }
            printf("\\n\");\n");
        }
        puts("printf(\"\\n\");\nreturn 0;\n}");
    }
    return 0;
}

台長: Morris
人氣(2,388) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA] 10469 - To Carry or not to Carry
此分類上一篇:[UVA] 11461 - Square Numbers

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文