The following program is my ACcepted code for NTHU-7648 .
It's a for everybody to learn and discuss.
If there is any mistake or comment, please let me know. :D
此乃NTHU 7648 的AC code!
點這裡看題目 Click here to see this Problem!
題目說 "特別注意:行末不得有空白。"
所以我以為是測資間需要一行空白,但是最後不能空白
但這樣會拿到很多WA
最後我在每個測資後面都輸出一行空白,就AC了...
//This program is for 7645 PA - Cake V.S. Rational number
//題目來源 Problem link: http://acm.cs.nthu.edu.tw/problem.php?pid=7645
#include<stdio.h>
#include<string.h>
int main()
{
int t, len1, len2, blank;
char up[20], down[20];
while(scanf("%d", &t) != EOF)
{
for(int test = 0; test < t; test++)
{
scanf("%s %s", &up, &down);
len1 = strlen(up);
len2 = strlen(down);
if(len1 < len2)
{
blank = (len2 - len1) / 2;
for(int i = 0; i<blank; i++)
printf(" ");
printf("%s\n", up);
for(int i = 0; i<len2; i++)
printf("-");
printf("\n%s\n", down);
}
else
{
blank = (len1 - len2) / 2;
printf("%s\n", up);
for(int i = 0; i<len1; i++)
printf("-");
printf("\n");
for(int i = 0; i<blank; i++)
printf(" ");
printf("%s\n", down);
}
printf("\n");
}
}
return 0;
}
Please feel free to use it after adding this blog as an reference. (http://autekroy.blogspot.tw) If there is any mistake or comment, please let me know. :D
歡迎使用與分享任何內容,但請記得標示此部落格為出處。(http://autekroy.blogspot.tw/) 如果有發現任何的錯誤與建議請留言或跟我連絡。 : )
It's a for everybody to learn and discuss.
If there is any mistake or comment, please let me know. :D
此乃NTHU 7648 的AC code!
歡迎一同討論學習,如有錯誤與任何建議請留言 : )
點這裡看題目 Click here to see this Problem!
所以我以為是測資間需要一行空白,但是最後不能空白
但這樣會拿到很多WA
最後我在每個測資後面都輸出一行空白,就AC了...
//This program is for 7645 PA - Cake V.S. Rational number
//題目來源 Problem link: http://acm.cs.nthu.edu.tw/problem.php?pid=7645
#include<stdio.h>
#include<string.h>
int main()
{
int t, len1, len2, blank;
char up[20], down[20];
while(scanf("%d", &t) != EOF)
{
for(int test = 0; test < t; test++)
{
scanf("%s %s", &up, &down);
len1 = strlen(up);
len2 = strlen(down);
if(len1 < len2)
{
blank = (len2 - len1) / 2;
for(int i = 0; i<blank; i++)
printf(" ");
printf("%s\n", up);
for(int i = 0; i<len2; i++)
printf("-");
printf("\n%s\n", down);
}
else
{
blank = (len1 - len2) / 2;
printf("%s\n", up);
for(int i = 0; i<len1; i++)
printf("-");
printf("\n");
for(int i = 0; i<blank; i++)
printf(" ");
printf("%s\n", down);
}
printf("\n");
}
}
return 0;
}
Please feel free to use it after adding this blog as an reference. (http://autekroy.blogspot.tw) If there is any mistake or comment, please let me know. :D
歡迎使用與分享任何內容,但請記得標示此部落格為出處。(http://autekroy.blogspot.tw/) 如果有發現任何的錯誤與建議請留言或跟我連絡。 : )
沒有留言:
張貼留言
請留下您的任何想法或建議!
Please leave any thought or comment!