杭电ACM1017题,我的代码为什么总是Presentation Error
#include<iostream>usingnamespacestd;intmain(){intN,i,n,m,a,b,count,kase;while(cin>>N)...
#include<iostream>
using namespace std;
int main()
{
int N, i, n, m, a, b, count,kase;
while (cin>>N)
{
for (i = N; i > 0; i--)
{
kase=0;
while (cin >> n >> m)
{
count = 0;
kase++;
if (n == 0 && m == 0) break;
for (a = 1; a < n-1; a++)
for (b = a + 1; b < n; b++)
if ((a*a + b*b + m) % (a*b) == 0)
count++;
cout << "Case" << kase << ":" << count << endl;
}
if (i!=1) cout << endl;
}
}
return 0;
} 展开
using namespace std;
int main()
{
int N, i, n, m, a, b, count,kase;
while (cin>>N)
{
for (i = N; i > 0; i--)
{
kase=0;
while (cin >> n >> m)
{
count = 0;
kase++;
if (n == 0 && m == 0) break;
for (a = 1; a < n-1; a++)
for (b = a + 1; b < n; b++)
if ((a*a + b*b + m) % (a*b) == 0)
count++;
cout << "Case" << kase << ":" << count << endl;
}
if (i!=1) cout << endl;
}
}
return 0;
} 展开
1个回答
2017-02-03
展开全部
Case后面有空格
AC答案:
#include <bits/stdc++.h>
using namespace std;
int main()
{
// freopen("in.txt","r",stdin);
int n,m,t;
scanf("%d",&t);
while(t--)
{
int kcase=0;
while(scanf("%d%d",&n,&m)!=EOF && n!=0)
{
kcase++;
int a,b,dig=0;
for(a=1; a<n; a++)
for(b=a+1; b<n; b++)
{
double temp=(double)(a*a+b*b+m)/(a*b);
if((temp-(int)temp)==0)
dig++;
}
cout<<"Case "<<kcase<<": "<<dig<<endl;
}
if(t)
cout<<endl;
}
return 0;
}
AC答案:
#include <bits/stdc++.h>
using namespace std;
int main()
{
// freopen("in.txt","r",stdin);
int n,m,t;
scanf("%d",&t);
while(t--)
{
int kcase=0;
while(scanf("%d%d",&n,&m)!=EOF && n!=0)
{
kcase++;
int a,b,dig=0;
for(a=1; a<n; a++)
for(b=a+1; b<n; b++)
{
double temp=(double)(a*a+b*b+m)/(a*b);
if((temp-(int)temp)==0)
dig++;
}
cout<<"Case "<<kcase<<": "<<dig<<endl;
}
if(t)
cout<<endl;
}
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询