| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:怎么不对~In Reply To:怎么不对~ Posted by:rainwhy at 2008-09-20 13:29:34 > #include <stdio.h>
> int main()
> {
> int a[100],b[100],n,i,j;
> scanf("%d",&n);
> for(i=0;i<n;i++)
> {
> scanf("%d %d",&a[i],&b[i]);
> }
> for(j=0;j<n;j++)
> {
> if(b[i]>=0&&a[j]>=b[j]&&(a[j]+b[j])>=0&&(a[i]+b[i])%2==0)
> {
> printf("%d %d\n",(a[j]+b[j])/2,(a[j]-b[j])/2); //因为你这里可能求出来的不是整数,所以错了
> }
> else printf("impossible\n");
> }
> return 0;
> }
我的程序正确:如下
#include <iostream>
using namespace std;
int main()
{
int n, a, b;
cin>>n;
while(n-->0)
{
cin>>a>>b;
if(a<b||(a%2==1&&b%2==0)||(a%2==0&&b%2==1))
cout<<"impossible"<<endl;
else
cout<<(a+b)/2<<" "<<(a-b)/2<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator