#7274: 錯在哪?(C++


kevinh60217 (伊歐)


#include <iostream>
using namespace std;
int main(void)
{
int x,i;
while(cin>>x)
{
if((x%4)==0)
{if((x%100)==0)
{if((x%400)==0)
cout <<"Case "<<i+1<<": a leap year"<<endl;
else
cout << "Case "<<i+1<<": a normal year"<<endl;
}
else
cout << "Case "<<i+1<<": a leap year"<<endl;}
else
cout << "Case "<<i+1<<": a normal year"<<endl;}

return 0;
}    
#7279: Re:錯在哪?(C++


akira0331 (小迷糊)


#include
using namespace std;
int main(void)
{
int x,i;
while(cin>>x)
{
if((x%4)==0)
{if((x%100)==0)
{if((x%400)==0)
cout <<"Case "<
else
cout << "Case "<
}
else
cout << "Case "<
else
cout << "Case "<

return 0;
}    

 
1.  i 沒有定初始值
2.  i 永遠等於1個固定值+1,並不會累加1,要改成 i++
#7283: Re:錯在哪?(C++


kevinh60217 (伊歐)


#include
using namespace std;
int main(void)
{
int x,i;
while(cin>>x)
{
if((x%4)==0)
{if((x%100)==0)
{if((x%400)==0)
cout <<"Case "<
else
cout << "Case "<
}
else
cout << "Case "<
else
cout << "Case "<

return 0;
}    

 
1.  i 沒有定初始值
2.  i 永遠等於1個固定值+1,並不會累加1,要改成 i++

#include <iostream>
using namespace std;
int main(void)
{
int x,i=1;
while(cin>>x)
{
if((x%4)==0)
{if((x%100)==0)
{if((x%400)==0)
cout <<"Case "<<i++<<": a leap year"<<endl;
else
cout << "Case "<<i++<<": a normal year"<<endl;
}
else
cout << "Case "<<i++<<": a leap year"<<endl;}
else
cout << "Case "<<i++<<": a normal year"<<endl;}

return 0;
}   

WA (line:1)
答案不正確

您的答案為: Case 1: a leap year 正確答案為: Case 1: a normal year 
我改好之後卻是WA,哪裡錯了?

#7289: Re:錯在哪?(C++


akira0331 (小迷糊)


#include
using namespace std;
int main(void)
{
int x,i;
while(cin>>x)
{
if((x%4)==0)
{if((x%100)==0)
{if((x%400)==0)
cout <<"Case "<
else
cout << "Case "<
}
else
cout << "Case "<
else
cout << "Case "<

return 0;
}    

 
1.  i 沒有定初始值
2.  i 永遠等於1個固定值+1,並不會累加1,要改成 i++

#include
using namespace std;
int main(void)
{
int x,i=1;
while(cin>>x)
{
if((x%4)==0)
{if((x%100)==0)
{if((x%400)==0)
cout <<"Case "<else
cout << "Case "<}
else
cout << "Case "<else
cout << "Case "<
return 0;
}   

WA (line:1)
答案不正確

您的答案為: Case 1: a leap year 正確答案為: Case 1: a normal year 
我改好之後卻是WA,哪裡錯了?



你寫的程式不符合題目的輸入方式

題目要求: 輸入的第一行有一個整數 n。接下來的 n 行每行有一個正整數 y,代表珊珊生日的西元年份。

請參照題目的輸入範例