2020-05-22 — 习题训练二-E

E - Candies and Two Sisters

题意:给定n,输出满足a+b=n,a>b的个数

解题思路:当n<=2时为0;n>2时,n是偶数为n/2-1,n是奇数为n/2.

ac代码:

#include<iostream>
using namespace std;
int main(){
	int t,n;
	cin>>t;
	while(t--){
		cin>>n;
		if(n<=2){
			cout<<"0"<<endl;
		}
		else{
			if(n%2==0) cout<<n/2-1<<endl;
			else cout<<n/2<<endl;
		}
	}
	return 0;
}

 

 
posted @ 2020-05-23 11:38  nanmoon  阅读(91)  评论(0编辑  收藏  举报