+ 1

[Solved] Balconies C++

Hello, can you help me please with the Balconies problem? I got stuck :/ cases 3,4,5 fail. This is my code: Thanks! #include <iostream> using namespace std; int main() { int h,w,A; int h1,w1,B; cin>>h>>w; cin>>h1>>w1; A=h*w; B=h1*w1; if (A>B) { cout<<"Apartment A"; } else { cout<<"Apartment B"; } return 0; }

1st Jul 2020, 9:17 PM
Iovanovici Kethrin - Ramona
Iovanovici Kethrin - Ramona - avatar
10 Respostas
+ 1
Try changing int into long long. There may be a case where the multiplication of 2 integers causes overflow. edit: or double
3rd Jul 2020, 5:45 PM
Bobby Fischer
Bobby Fischer - avatar
+ 9
Try this cin»h; getchar(); cin»w; do the same for the other one
3rd Jul 2020, 6:19 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 8
It will be better if you will send question link we will check it . your code have no errors but without link we cannot test your code
3rd Jul 2020, 5:39 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
I don’t know about the question but there are some ways your code can go wrong: 1. What happens if A = B? you don’t have that condition. 2. What if (h) and (w) are not integers?
1st Jul 2020, 9:34 PM
Bobby Fischer
Bobby Fischer - avatar
+ 1
[Solved] Thanks for help!
3rd Jul 2020, 8:30 PM
Iovanovici Kethrin - Ramona
Iovanovici Kethrin - Ramona - avatar
0
I also tried the case where both apartments have the same (h*w), but still don't work
1st Jul 2020, 9:39 PM
Iovanovici Kethrin - Ramona
Iovanovici Kethrin - Ramona - avatar
0
You are trying to determine which of two apartments has a larger balcony. Both balconies are rectangles, and you have the length and width, but you need the area. Task Evaluate the area of two different balconies and determine which one is bigger. Input Format Your inputs are two strings where the measurements for height and width are separated by a comma. The first one represents apartment A, the second represents apartment B. Output Format: A string that says whether apartment A or apartment B has a larger balcony. Sample Input '5,5' '2,10' Sample Output Apartment A
3rd Jul 2020, 5:41 PM
Iovanovici Kethrin - Ramona
Iovanovici Kethrin - Ramona - avatar
0
[Solved] Balconies JAVA, using some Regex : enjoy import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String txt1 = scan.nextLine(); String txt2 = scan.nextLine(); int nbre1 = 1; int nbre2 = 1; for (String i: txt1.split(",")){ String t = i.replaceAll("[^0-9]",""); int apt1 = Integer.parseInt(t); nbre1 = nbre1*apt1; } for (String j: txt2.split(",")){ String t = j.replaceAll("[^0-9]",""); int apt2 = Integer.parseInt(t); nbre2 = nbre2*apt2; } if(nbre1>nbre2){ System.out.println("Apartment A"); }else{ System.out.println("Apartment B"); } } }
21st Jan 2022, 12:38 PM
Moussa Diallo
Moussa Diallo - avatar
0
#include <iostream> using namespace std; int main() { string A,a1,a2; cin>>A; int t,e; t=A.find(","); for(int i=0;i<t;i++){ a1+=A[i] ; } for(int i=t;i<size(A);i++){ a2+=A[i+1]; } int h=stoi(a1); int w=stoi(a2); int A2=h*w; string B,b1,b2; cin>>B; int t1,e1; t1=B.find(","); for(int i=0;i<t1;i++){ b1+=B[i] ; } for(int i=t1;i<size(B);i++){ b2+=B[i+1]; } int h1=stoi(b1); int w1=stoi(b2); int A3=h1*w1; if(A2>A3){ cout<<"Apartment A"; } else{ cout<<"Apartment B"; } return 0; }
29th Mar 2024, 5:03 PM
РАДЖАН ЖУМАНОВИЧ
РАДЖАН ЖУМАНОВИЧ - avatar
- 1
if you could post the question, that would be great
1st Jul 2020, 9:40 PM
Bobby Fischer
Bobby Fischer - avatar