The following program is my ACcepted code for Codeforces -379A .
It's a for everybody to learn and discuss.
If there is any mistake or comment, please let me know. :D
此乃Codeforces 379A 的AC code!
//This program is for Codeforces 379A New Year Candles
//題目來源 Problem link: http://codeforces.com/problemset/problem/379/A
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a, b;
int ans, left, tmp;
while(scanf("%d %d", &a, &b) != EOF)
{
ans = 0;
left = 0;//indicate went out candles
do{
if(left >= b)
{
tmp = left % b;
a = left / b;
left = tmp;
}
ans += a;
left = left + a;
//printf("ans:%d a:%d left:%d\n", ans, a, left);
}while(left >= b);
printf("%d\n", ans);
}
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
此乃Codeforces 379A 的AC code!
歡迎一同討論學習,如有錯誤與任何建議請留言 : )
//This program is for Codeforces 379A New Year Candles
//題目來源 Problem link: http://codeforces.com/problemset/problem/379/A
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a, b;
int ans, left, tmp;
while(scanf("%d %d", &a, &b) != EOF)
{
ans = 0;
left = 0;//indicate went out candles
do{
if(left >= b)
{
tmp = left % b;
a = left / b;
left = tmp;
}
ans += a;
left = left + a;
//printf("ans:%d a:%d left:%d\n", ans, a, left);
}while(left >= b);
printf("%d\n", ans);
}
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!