以下是我的錯誤報告
您的答案為: f2752674349339634925109431351390543043102385172852692458764260471789059534961180576127198631499007338 正確答案為: 542752674349339634925109431351390543043102385172852692458764260471789059534961180576127198631499007338
請各位幫我看看到底為啥會出現「f」這個神奇的東西
code:
#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
int main()
{
char ans[10000],temp[10000];
int ansLen,tempLen,carry;
ansLen = tempLen = 0;
memset(ans,'0',sizeof(ans));
while(~scanf("%s",&temp)){
if(strlen(temp) == 1&&temp[0] == '0'){
break;
}
tempLen = strlen(temp);
carry = 0;
for(int i = 0;i < tempLen/2;i++){
swap(temp[i],temp[tempLen - i - 1]);
}
for(int i = 0;i < tempLen;i++){
ans[i] += temp[i] - 48;
if(ans[i] - 48 >= 10){
ans[i] -= 10;
ans[i+1]++;
if(i == ansLen - 1){
ansLen++;
}
}
}
ansLen = max(ansLen,tempLen);
//printf("len = %d\n",ansLen);
}
for(int i = ansLen - 1;i >= 0;i--){
printf("%c",ans[i]);
}
return 0;
}
以下是我的錯誤報告
您的答案為: f2752674349339634925109431351390543043102385172852692458764260471789059534961180576127198631499007338 正確答案為: 542752674349339634925109431351390543043102385172852692458764260471789059534961180576127198631499007338
請各位幫我看看到底為啥會出現「f」這個神奇的東西
code:
#include
#include
#include
using namespace std;
int main()
{
char ans[10000],temp[10000];
int ansLen,tempLen,carry;
ansLen = tempLen = 0;
memset(ans,'0',sizeof(ans));
while(~scanf("%s",&temp)){
if(strlen(temp) == 1&&temp[0] == '0'){
break;
}
tempLen = strlen(temp);
carry = 0;
for(int i = 0;i < tempLen/2;i++){
swap(temp[i],temp[tempLen - i - 1]);
}
for(int i = 0;i < tempLen;i++){
ans[i] += temp[i] - 48;
if(ans[i] - 48 >= 10){
ans[i] -= 10;
ans[i+1]++;
if(i == ansLen - 1){
ansLen++;
}
}
}
ansLen = max(ansLen,tempLen);
//printf("len = %d\n",ansLen);
}
for(int i = ansLen - 1;i >= 0;i--){
printf("%c",ans[i]);
}
return 0;
}
因該是最前面那位沒有進位,加起來就成了' f '
f 的編碼 102