题解 | #奇偶统计#
奇偶统计
https://www.nowcoder.com/practice/04de8eb0ecab426fa6be3ae99af17210
#include<stdio.h>
int main()
{
int a,sum1=0,sum2=0;
scanf("%d",&a);
while(a>=1)
{if(a%2==0)
{
sum1=sum1+1;
a=a-2;
sum2=sum1;
}
else
{
sum2=sum2+1;
a=a-2;
sum1=sum2-1;
}
}
printf("%d %d",sum2,sum1);
return 0;
int main()
{
int a,sum1=0,sum2=0;
scanf("%d",&a);
while(a>=1)
{if(a%2==0)
{
sum1=sum1+1;
a=a-2;
sum2=sum1;
}
else
{
sum2=sum2+1;
a=a-2;
sum1=sum2-1;
}
}
printf("%d %d",sum2,sum1);
return 0;
}
//尝试用循环