UVa 10783 Odd Sum
似乎有不需要任何if判斷的寫法? 還沒參透
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 10783 - Odd Sum | |
* Last Modified: 2009.11.27 | |
* Author: chchwy | |
*/ | |
#include<cstdio> | |
int main() | |
{ | |
int numCase; | |
scanf("%d", &numCase); | |
for (int i = 1; i <= numCase; ++i) | |
{ | |
int a, b; | |
scanf("%d %d", &a, &b); | |
if (a % 2 == 0)a++; | |
if (b % 2 == 0)b--; | |
printf("Case %d: %d\n", i, (a + b) * (b - a + 2) / 4 ); | |
} | |
return 0; | |
} |
a+=a%2;類似這樣勒
回覆刪除不知道有沒有比較快...
回覆刪除a=(a%2)?a:a+1;
回覆刪除