my code : https://onlinegdb.com/HkhNGSoAS
problem : FLOW005 Problem - CodeChef
You are not printing a new line.
Add endl or “\n” after cout<<s and your code should work fine.
Program output should strictly match the problem output section.
2 Likes
I spent a lot of time to think about this silly mistake…
thanks.
1 Like
@aditigedam Instead of declaring too many variables as in your source code, you can use an if-else
construct inside the loop to complete the task.
Refer to the below code:
#include<bits/stdc++.h>
using namespace std;
int main(void) {
int test;
std :: cin >> test;
while(test--) {
unsigned int n, number_of_notes;
std :: cin >> n;
number_of_notes = 0;
while(n) {
if(n >= 100) {
number_of_notes += n / 100;
n %= 100;
} else if(n >= 50) {
number_of_notes += n / 50;
n %= 50;
} else if(n >= 10) {
number_of_notes += n / 10;
n %= 10;
} else if(n >= 5) {
number_of_notes += n / 5;
n %= 5;
} else if(n >= 2) {
number_of_notes += n / 2;
n %= 2;
} else {
number_of_notes += n;
n = 0;
}
}
std :: cout << number_of_notes << endl;
}
return 0;
}
You can refer to the solutions in other programming languages here: Competitive-Programming/Code-Chef/Smallest-Numbers-of-Notes at master · strikersps/Competitive-Programming · GitHub