#8868: (新手)不懂為何逾時,求解


NookBy1 (who)


#include <iostream>
using namespace std;
int a[11] = { 0 };

int main()
{
char i;
int t;
char j;
while (1)
{
cin >> a[0];
if (a[0] != 0)
{
for (i = 0; i < a[0]; i++)
{
t = 1 + (i * 5);
for (j = 0; j <= 3; j++)
{
cin >> a[t + j];
}
if (a[t + 1] - a[t] == a[t + 2] - a[t + 1])
{
a[t + 4] = a[t + 3] + (a[t + 1] - a[t]);
}
if (a[t + 1] / a[t] == a[t + 2] / a[t + 1])
{
a[t + 4] = a[t + 3] * (a[t + 1] / a[t]);
}
}
t = 1;
a[0] = 0;
cout << a[t] << " " << a[t + 1] << " " << a[t + 2] << " " << a[t + 3] << " " << a[t + 4] << endl;
cout << a[t+5] << " " << a[t + 6] << " " << a[t + 7] << " " << a[t + 8] << " " << a[t + 9] << endl;
}
}
return 0;
}
#8869: Re:(新手)不懂為何逾時,求解


silithus (希利蘇斯)


#include
using namespace std;
int a[11] = { 0 };

int main()
{
char i;
int t;
char j;
while (1)
{
cin >> a[0];
if (a[0] != 0)
{
for (i = 0; i < a[0]; i++)
{
t = 1 + (i * 5);
for (j = 0; j <= 3; j++)
{
cin >> a[t + j];
}
if (a[t + 1] - a[t] == a[t + 2] - a[t + 1])
{
a[t + 4] = a[t + 3] + (a[t + 1] - a[t]);
}
if (a[t + 1] / a[t] == a[t + 2] / a[t + 1])
{
a[t + 4] = a[t + 3] * (a[t + 1] / a[t]);
}
}
t = 1;
a[0] = 0;
cout << a[t] << " " << a[t + 1] << " " << a[t + 2] << " " << a[t + 3] << " " << a[t + 4] << endl;
cout << a[t+5] << " " << a[t + 6] << " " << a[t + 7] << " " << a[t + 8] << " " << a[t + 9] << endl;
}
}
return 0;
}

沒有退出條件,死迴圈。。。
#8870: Re:(新手)不懂為何逾時,求解


NookBy1 (who)


把無限迴圈拿掉會輸出短少


#8877: Re:(新手)不懂為何逾時,求解


gkfriend (Edward)


把無限迴圈拿掉會輸出短少
 

沒學過 C++ ,但個人猜測你的問題可在新手題解決。

請參考: 

Sample code of C++ :

#include
using namespace std;
int main() {
     string s;
     while(cin >> s){
          cout << "hello, "<< s << endl;
     }
     return 0;
}

 原因請參考使用手冊 :

 

#8878: Re:(新手)不懂為何逾時,求解


gkfriend (Edward)




忘了附連結

http://zerojudge.tw/UserGuide.jsp  

#8879: Re:(新手)不懂為何逾時,求解


gkfriend (Edward)




忘了附連結

http://zerojudge.tw/UserGuide.jsp