spoj http://www.spoj.com/problems/JULKA/
spoj http://www.spoj.com/problems/JULKA/
//explain below for loop what is actually being done in this loop//
for(i=k-1, j=a=f=0; i>=0; i--)
{
b = (a*10 + temp[i]-'0') / 2; //explain
a = (a*10 + temp[i]-'0') % 2;//explain
if(b) f = 1;//explain
if(f) klaudia[j++] = b+'0';//explain
}
if(!j) j++;//explain
klaudia[j] = 0;//explain
for(i=len1-1, j=len2-1, k=c=0; i>=0; i--, j--, k++)
{
a = total[i]-'0';//explain
b = j>=0? diff[j]-'0' : 0;//explain
if(a < b+c)
{
temp[k] = (10+a-b-c) + '0';//explain
c = 1;//explain }
else
{
temp[k] = a-b-c + '0';//explain
c = 0;//explain
}
}
temp[k] = 0;//explain
解释在上面的两个 for 循环中正在做什么,为什么我们要除以和调制 2。 加 0 的意义是什么
第一个循环是将 temp[] 中表示为字符串的十进制数除以 2。/2 实际上是将一个数字除以 2,%2 是将余数应用于下一个数字 - 这就是为什么它随后乘以 10。
"0"的加法和减法用于将原始数字与其 ASCII 表示形式之间的个位数转换为字符。
相关文章:
- Problems with std::cin.fail()
- QT GStreamer Windows linker problems
- SPOJ 上的主生成器 PRIME1
- Problems with emscripten (WebAssembly)
- SPOJ中的运行时错误
- 代码在代码块上运行良好,但在 SPOJ 上无法运行
- 为什么当我从语句检查中删除"+ mod"时,以下程序给出错误的答案。问题链接:https://www.codechef.com/problems/FFC219B
- Problems with QByteArray::right
- 对于 spoj 的问题 TRT(对待奶牛)的 dp 的最佳方法是什么?
- 当我的代码工作正常时,为什么在SPOJ中遇到运行时(Sigabrt)错误
- TLE试图使用Dinic算法在SPOJ上求解Fastflow
- glutPassiveMotionFunc problems
- 如何提高主生成器 (SPOJ) 解决方案的效率
- Problems in using ?: as if statement in C++
- MPI Isend and Irecv problems
- 为什么我在SPOJ上为Buglife获得WA
- C++: problems with strtok
- spoj http://www.spoj.com/problems/JULKA/
- 我的系统出错了,程序运行正常,但 submittionhttp://www.spoj.com/problems/NITT
- 解决 SPOJ www.spoj.com/problems/PRHYME/ 的正确方法是什么?