I want to divide the two numbers read in one line











up vote
-3
down vote

favorite
1












I have a school assignment. But I have not implemented some of the code.
After reading the three digits a and b in one line, read this numbers in reverse.
Finally, it is a matter of comparing two readings and outputting a large number.



I implemented this in C ++, but I could not divide the two numbers read in one line.



This is an example



-input :



123 451



-output :



321



This is my code



#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(void){
char input[8];
cin.getline(input,8,'n');

string compare1="";
string compare2="";

// I want to parsing this input string(line) to compare1 / compare2
// but I can’t.

reverse(compare1.begin(), compare1.end());
reverse(compare2.begin(), compare2.end());

if(compare1.compare(compare2)<0){
cout<<compare2<<endl;
}else{
cout<<compare1<<endl;
}
return 0;
}



bool next = false;
for(int i=0; input[i]!=''; i++){
if(input[i] == ' '){
next = true;
continue;
}

if(next){
compare2 += input[i];
}else {
compare1 += input[i];
}
}









share|improve this question









New contributor




Vincent VC is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    double a, b; cin >> a >> b; cout << a/b;
    – Matthieu Brucher
    Nov 18 at 14:19










  • Why don't you simply use intor double instead of string for the input?
    – πάντα ῥεῖ
    Nov 18 at 14:20












  • What is the code after main(). Your code format is bad but the line after return 0 is all that is in main. I was going to fix the formatting but when I see invalid code like this I just leave it alone.
    – drescherjm
    Nov 18 at 14:21

















up vote
-3
down vote

favorite
1












I have a school assignment. But I have not implemented some of the code.
After reading the three digits a and b in one line, read this numbers in reverse.
Finally, it is a matter of comparing two readings and outputting a large number.



I implemented this in C ++, but I could not divide the two numbers read in one line.



This is an example



-input :



123 451



-output :



321



This is my code



#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(void){
char input[8];
cin.getline(input,8,'n');

string compare1="";
string compare2="";

// I want to parsing this input string(line) to compare1 / compare2
// but I can’t.

reverse(compare1.begin(), compare1.end());
reverse(compare2.begin(), compare2.end());

if(compare1.compare(compare2)<0){
cout<<compare2<<endl;
}else{
cout<<compare1<<endl;
}
return 0;
}



bool next = false;
for(int i=0; input[i]!=''; i++){
if(input[i] == ' '){
next = true;
continue;
}

if(next){
compare2 += input[i];
}else {
compare1 += input[i];
}
}









share|improve this question









New contributor




Vincent VC is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    double a, b; cin >> a >> b; cout << a/b;
    – Matthieu Brucher
    Nov 18 at 14:19










  • Why don't you simply use intor double instead of string for the input?
    – πάντα ῥεῖ
    Nov 18 at 14:20












  • What is the code after main(). Your code format is bad but the line after return 0 is all that is in main. I was going to fix the formatting but when I see invalid code like this I just leave it alone.
    – drescherjm
    Nov 18 at 14:21















up vote
-3
down vote

favorite
1









up vote
-3
down vote

favorite
1






1





I have a school assignment. But I have not implemented some of the code.
After reading the three digits a and b in one line, read this numbers in reverse.
Finally, it is a matter of comparing two readings and outputting a large number.



I implemented this in C ++, but I could not divide the two numbers read in one line.



This is an example



-input :



123 451



-output :



321



This is my code



#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(void){
char input[8];
cin.getline(input,8,'n');

string compare1="";
string compare2="";

// I want to parsing this input string(line) to compare1 / compare2
// but I can’t.

reverse(compare1.begin(), compare1.end());
reverse(compare2.begin(), compare2.end());

if(compare1.compare(compare2)<0){
cout<<compare2<<endl;
}else{
cout<<compare1<<endl;
}
return 0;
}



bool next = false;
for(int i=0; input[i]!=''; i++){
if(input[i] == ' '){
next = true;
continue;
}

if(next){
compare2 += input[i];
}else {
compare1 += input[i];
}
}









share|improve this question









New contributor




Vincent VC is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I have a school assignment. But I have not implemented some of the code.
After reading the three digits a and b in one line, read this numbers in reverse.
Finally, it is a matter of comparing two readings and outputting a large number.



I implemented this in C ++, but I could not divide the two numbers read in one line.



This is an example



-input :



123 451



-output :



321



This is my code



#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(void){
char input[8];
cin.getline(input,8,'n');

string compare1="";
string compare2="";

// I want to parsing this input string(line) to compare1 / compare2
// but I can’t.

reverse(compare1.begin(), compare1.end());
reverse(compare2.begin(), compare2.end());

if(compare1.compare(compare2)<0){
cout<<compare2<<endl;
}else{
cout<<compare1<<endl;
}
return 0;
}



bool next = false;
for(int i=0; input[i]!=''; i++){
if(input[i] == ' '){
next = true;
continue;
}

if(next){
compare2 += input[i];
}else {
compare1 += input[i];
}
}






c++






share|improve this question









New contributor




Vincent VC is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Vincent VC is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 18 at 14:21









πάντα ῥεῖ

71.2k970133




71.2k970133






New contributor




Vincent VC is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 18 at 14:18









Vincent VC

11




11




New contributor




Vincent VC is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Vincent VC is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Vincent VC is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 1




    double a, b; cin >> a >> b; cout << a/b;
    – Matthieu Brucher
    Nov 18 at 14:19










  • Why don't you simply use intor double instead of string for the input?
    – πάντα ῥεῖ
    Nov 18 at 14:20












  • What is the code after main(). Your code format is bad but the line after return 0 is all that is in main. I was going to fix the formatting but when I see invalid code like this I just leave it alone.
    – drescherjm
    Nov 18 at 14:21
















  • 1




    double a, b; cin >> a >> b; cout << a/b;
    – Matthieu Brucher
    Nov 18 at 14:19










  • Why don't you simply use intor double instead of string for the input?
    – πάντα ῥεῖ
    Nov 18 at 14:20












  • What is the code after main(). Your code format is bad but the line after return 0 is all that is in main. I was going to fix the formatting but when I see invalid code like this I just leave it alone.
    – drescherjm
    Nov 18 at 14:21










1




1




double a, b; cin >> a >> b; cout << a/b;
– Matthieu Brucher
Nov 18 at 14:19




double a, b; cin >> a >> b; cout << a/b;
– Matthieu Brucher
Nov 18 at 14:19












Why don't you simply use intor double instead of string for the input?
– πάντα ῥεῖ
Nov 18 at 14:20






Why don't you simply use intor double instead of string for the input?
– πάντα ῥεῖ
Nov 18 at 14:20














What is the code after main(). Your code format is bad but the line after return 0 is all that is in main. I was going to fix the formatting but when I see invalid code like this I just leave it alone.
– drescherjm
Nov 18 at 14:21






What is the code after main(). Your code format is bad but the line after return 0 is all that is in main. I was going to fix the formatting but when I see invalid code like this I just leave it alone.
– drescherjm
Nov 18 at 14:21














1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










You can make the part that you want to make



  bool next = false;
for(int i=0; input[i]!=''; i++){
if(input[i] == ' '){
next = true;
continue;
}

if(next){
compare2 += input[i];
}else {
compare1 += input[i];
}
}





share|improve this answer

















  • 3




    Huh what? Care to explain please.
    – πάντα ῥεῖ
    Nov 18 at 14:20










  • What is different between this and the code that is after main()??
    – drescherjm
    Nov 18 at 18:59











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Vincent VC is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53361862%2fi-want-to-divide-the-two-numbers-read-in-one-line%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










You can make the part that you want to make



  bool next = false;
for(int i=0; input[i]!=''; i++){
if(input[i] == ' '){
next = true;
continue;
}

if(next){
compare2 += input[i];
}else {
compare1 += input[i];
}
}





share|improve this answer

















  • 3




    Huh what? Care to explain please.
    – πάντα ῥεῖ
    Nov 18 at 14:20










  • What is different between this and the code that is after main()??
    – drescherjm
    Nov 18 at 18:59















up vote
1
down vote



accepted










You can make the part that you want to make



  bool next = false;
for(int i=0; input[i]!=''; i++){
if(input[i] == ' '){
next = true;
continue;
}

if(next){
compare2 += input[i];
}else {
compare1 += input[i];
}
}





share|improve this answer

















  • 3




    Huh what? Care to explain please.
    – πάντα ῥεῖ
    Nov 18 at 14:20










  • What is different between this and the code that is after main()??
    – drescherjm
    Nov 18 at 18:59













up vote
1
down vote



accepted







up vote
1
down vote



accepted






You can make the part that you want to make



  bool next = false;
for(int i=0; input[i]!=''; i++){
if(input[i] == ' '){
next = true;
continue;
}

if(next){
compare2 += input[i];
}else {
compare1 += input[i];
}
}





share|improve this answer












You can make the part that you want to make



  bool next = false;
for(int i=0; input[i]!=''; i++){
if(input[i] == ' '){
next = true;
continue;
}

if(next){
compare2 += input[i];
}else {
compare1 += input[i];
}
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 18 at 14:19









yeregi

792




792








  • 3




    Huh what? Care to explain please.
    – πάντα ῥεῖ
    Nov 18 at 14:20










  • What is different between this and the code that is after main()??
    – drescherjm
    Nov 18 at 18:59














  • 3




    Huh what? Care to explain please.
    – πάντα ῥεῖ
    Nov 18 at 14:20










  • What is different between this and the code that is after main()??
    – drescherjm
    Nov 18 at 18:59








3




3




Huh what? Care to explain please.
– πάντα ῥεῖ
Nov 18 at 14:20




Huh what? Care to explain please.
– πάντα ῥεῖ
Nov 18 at 14:20












What is different between this and the code that is after main()??
– drescherjm
Nov 18 at 18:59




What is different between this and the code that is after main()??
– drescherjm
Nov 18 at 18:59










Vincent VC is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















Vincent VC is a new contributor. Be nice, and check out our Code of Conduct.













Vincent VC is a new contributor. Be nice, and check out our Code of Conduct.












Vincent VC is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53361862%2fi-want-to-divide-the-two-numbers-read-in-one-line%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Create new schema in PostgreSQL using DBeaver

Deepest pit of an array with Javascript: test on Codility

Costa Masnaga