错误的答案:内存挂了。
#include<iostream>
#include<string>
using namespace std;
int function(int i, int j, int k)
{
if( 1 == k || 2 == k)
{
return 1;
}
return (function(i, j , k - 1) * i + function(i, j , k-2) * j)%7;
}
int main()
{
int iFirst, iSecond, iThird;
while(cin >> iFirst >> iSecond >> iThird )
{
if(iFirst == 0 && iSecond == 0 && 0 == iThird)
{
return 0;
}
cout << function(iFirst, iSecond, iThird) << endl;;
}
return 0;
}
错误答案:时间超了
#include<iostream>
using namespace std;
int main()
{
int iFirst, iSecond, iThird;
while(cin >> iFirst >> iSecond >> iThird )
{
if(iFirst == 0 && iSecond == 0 && 0 == iThird)
{
return 0;
}
if(iThird <= 2)
{
cout << "1" << endl;
}
else
{
int iFormer = 1;
int iMid = 1, iLater;
for(int i = 3 ; i <= iThird; i++)
{
iLater = ( iFormer*iSecond + iMid*iFirst )%7;
//cout << i << " : " << iLater <<endl;
iFormer = iMid;
iMid = iLater;
}
cout << iLater << endl;
}
}
return 0;
}
题目:点击打开链接
参考答案:点击打开链接
思路:点击打开链接