| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:自己的代码一直TLE,求大神帮忙检查一下In Reply To:Re:自己的代码一直TLE,求大神帮忙检查一下 Posted by:08122224 at 2021-11-22 00:45:05 1、先对3个原始数据倒序存储,加的时候能简化很多
2、str不要一直拼接,先申请一块大的能提高效率。
3、两数按位加不需要使用%,最大为19,改用-10能优化
int Add(char *operand1, char *operand2, char *result)
{
int tempSub = 2 * '0';
int i = 0;
for (i = 0; i < MAX_LEN; ++i) {
result[i] = operand1[i] + operand2[i] + result[i];
if (result[i] == 0) {
break;
}
if(result[i] >= tempSub) {
result[i] -= tempSub;
} else if (result[i] >= '0') {
result[i] -= '0';
}
if (result[i] > 9) {
result[i+1] += 1;
result[i] -= 10;
}
result[i] += '0';
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator