我正在撰写一份方案,其中总结了一份文本档案中首批50位数的十位数。 容易,我得到正确答案,但我试图理解一些似乎正在经历的令人厌恶的事情。 第一个计算线如以下方案产出所示:
8549904804355727945614717320-7-60-4-3-2-7-3-4-8-7-7-6-1-840-9-5-2-3-39622981389563771795892386478402037366780930326737553
在对该项权利的意见做出修改后,它就产生了以下结果:
97414719961102146325906539660-4-7-2-4-4-3-4-8-2-8-3-8-2-870-8-5-2-3-39622981389563771795892386478402037366780930326737553
I m having trouble understanding
1) how what I output could somehow affect the future values it output.
2) How the dashes get into the program.
注:产出是所有指示数的总和。
char file[] = "nums.txt";
ifstream ss(file);
string iString;
string sarr[100];
int sum[100];
while(getline(ss, iString,
)) {
sarr[i] = iString;
i++;
}
ss.close();
cout << sarr[0] << endl << endl; //or cout<<(int)sarr[0][3]-48<<endl<<endl;
for(int i = 99; i >= 0; i--) {
sum[i] = 0;
for(int j = 0; j < 100; j++) {
sum[i] += (int)sarr[j][i];
}
sum[i] -= 4800;//since 100 strings and 0 in ascii is 48 subtract 48*100
}
for(int i = 99; i > 0; i--) {
sum[i-1] += sum[i] / 10;
sum[i] = sum[i] % 10;
cout << sum[i];
}
cout << sum[0] << endl << endl;