如何将java转换为C ++? [英] How do I convert java to C++?
本文介绍了如何将java转换为C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿......
我能帮助您将以下Java代码转换为C ++吗?
Hey...
Can I please have some help converting the following Java code into C++?
var a, b, c, d, s : int
var nikkySteps, nikkyDistance : int
var byronSteps, byronDistance : int
var next, sgn : int
get a, b, c, d, s
nikkySteps := 0
nikkyDistance := 0
next := a
sgn := 1
loop
exit when nikkySteps + next >= s
nikkySteps := nikkySteps + next
nikkyDistance := nikkyDistance + sgn * next
if sgn = 1 then
next := b
else
next := a
end if
sgn := sgn * -1
end loop
nikkyDistance := nikkyDistance + sgn * (s - nikkySteps)
byronSteps := 0
byronDistance := 0
next := c
sgn := 1
loop
exit when byronSteps + next >= s
byronSteps := byronSteps + next
byronDistance := byronDistance + sgn * next
if sgn = 1 then
next := d
else
next := c
end if
sgn := sgn * -1
end loop
byronDistance := byronDistance + sgn * (s - byronSteps)
if nikkyDistance > byronDistance then
put "Nikky"
elsif nikkyDistance < byronDistance then
put "Byron"
else
put "Tied"
end if
谢谢
我尝试过:
Thanks
What I have tried:
#include <iostream>
using namespace std;
int main() {
int a,b,c,d,s
int nikkySteps, NikkyDistance
int byronSteps, byrinDistance
int next, sgn
cin >> a;
cin >> b;
cin >> c;
cin >> s;
cin >> d;
int nikkySteps = 0;
int nikkyDistance = 0;
int next = a;
int sgn = 1;
*confused*
nikkySteps = nikkySteps + next;
nikkyDistance = nikkyDistance + sgn * next;
if (sgn = 1 ){
next = b
} else {
next = a
}
sgn = sgn * -1
*confused*
nikkyDistance = nikkyDistance + sgn * (s = nikkySteps);
int byronSteps = 0
int byronDistance = 0
int next = c
int sgn = 1
*confused"
byronSteps = byronSteps + next;
byronDistance = byronDistance + sgn * next;
if (sgn = 1 ){
next = d
} else {
next = c
}
sgn = sgn * -1
byronDistance = byronDistance + sgn * (s - byronSteps)
if (nikkyDistance > byronDistance ) {
cout << "Nicky" << endl;
} else if (nikkyDistance < byronDistance ) {
cout << "Byron" << endl;
} else {
cout << "Tied" << endl;
}
return 0;
}
推荐答案
您必须了解上述代码的作用。你必须从头开始重写它!
如果你很懒,你可以使用在线转换器。注意:它不是Java,而是Delphi。可在此处找到可用转换器的列表: .NET代码转换 - 转换代码 [ ^ ]
You have to understand what above code does. And you have to rewrite it from scratch!
In case you're lazy, you can use online converter. Note: it's not Java, it's Delphi. A list of available converters, you'll find here: .NET Code Conversion - Convert Your Code[^]
这篇关于如何将java转换为C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文