这是我正在谈论的问题 http://projecteuler.net/index.php?section=problems&id=99
我的代码将正确编译和运行。我猜计算是它搞砸的地方。它告诉我第 633 行是最大的(欧拉项目说的不正确)。
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int poww(int base, int exp);
int main()
{
//ignore messy/unused variables. I am desperate
int lineNumber = 0;
string line;
int answerLine = 0;
int max =0;
int lineNum = 0;
int answer =0;
ifstream inFile;
size_t location;
string temp1,temp2;
int tempMax = 0;
int base,exp = 0;
inFile.open("C:\\Users\\myYser\\Desktop\\base_exp.txt");
while(getline(inFile,line))
{
lineNumber++;
location = line.find(",");
temp1 = line.substr(0,(int(location)));
temp2 = line.substr((int(location)+1),line.length());
//cout << temp1 << " " << temp2 << endl;
base = atoi(temp1.c_str());
exp = atoi(temp2.c_str());
tempMax= poww(base,exp);
if (tempMax > max){
max = tempMax;
answer = base;
answerLine = lineNumber;
}
}
cout << answer << " " << answerLine;
cin.get();
return 0;
}
int poww(int base, int exp)
{
int result = 1;
while (exp)
{
if (exp & 1)
result *= base;
exp >>= 1;
base *= base;
}
return result;
}