永发信息网

acm题为什么输出一直为0啊

答案:1  悬赏:80  手机版
解决时间 2021-03-23 06:29
  • 提问者网友:精神病院里
  • 2021-03-22 21:46
acm题为什么输出一直为0啊
CXB join an interview,the interviewer give him a problem.He is asked to reverse every number and calculate the summation of the new number.For instance,there are two numbers 10 and 14,the answer after reverse is 1 and 41,so the final answer is 1+41=42.
Input
The first line of the input contains n.(nx>>y;
while(x>0)
{
x=x/10;
n=n+1;
}
for(j=n;j>0;j--)
{
a=x%10;
b=b+a*(10^(j-1));
x=x/10;
}
while(y>0)
{
y=y/10;
m=m+1;
}
for(j=m;j>0;j--)
{
a=y%10;
c=c+a*(10^(j-1));
y=y/10;
}
d=c+b;
cout
最佳答案
  • 五星知识达人网友:纵马山川剑自提
  • 2021-03-22 23:23

#include
using namespace std;
int main()
{
int x,y,N,i,j,n=0,b=0,c=0,d,a,m=0;
cin>>N;
for(i=1;i>x>>y;
while(x>0)
{
x=x/10;
n=n+1;
}
for(j=n;j>0;j--)
{
a=x%10;
b=b+a*(10^(j-1));//^并不是表示次方
x=x/10;
}
while(y>0)
{
y=y/10;
m=m+1;
}
for(j=m;j>0;j--)
{
a=y%10;
c=c+a*(10^(j-1));
y=y/10;
}
d=c+b;
couty;
x=chang(x);
 y=chang(y);
 d=x+y;
cout
再问: 结果对了我也明白我的错了 但交上去是超时
再答: 是我的超时了吗? 可以改用scanf,printf这样会快一些
再问: 是 差了0.01秒 我不会改
再答: 题目地址可以地一下吗? #include #include using namespace std; int chang(int n) { int ret=0; while(n>0) { ret=ret*10+n%10; n/=10; } return ret; } int main() { int x,y,N,i,j,n=0,b=0,c=0,d,a,m=0; //cin>>N; scanf(%d,&N); for(i=1;i>x>>y; scanf(%d%d,&x,&y); x=chang(x); y=chang(y); d=x+y; //cout


我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯