Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions bottle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <iostream>
using namespace std;

int main() {
int numBottles, numExchange;
cin >> numBottles >> numExchange;

int total = numBottles;
int empty = numBottles;

while (empty >= numExchange) {
int newBottles = empty / numExchange;
total += newBottles;
empty = (empty % numExchange) + newBottles;
}

cout << total << endl;
return 0;
}
38 changes: 38 additions & 0 deletions dash.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <bits/stdc++.h>
using namespace std;

int main() {
string s = "5F3Z-2e-9-w"; // input string
int k = 4; // group size

string temp = "";

// 1. Remove dashes and convert to uppercase
for (char c : s) {
if (c != '-') {
temp += toupper(c);
}
}

// 2. Build result from the end
string result = "";
int count = 0;

for (int i = temp.size() - 1; i >= 0; i--) {
result.push_back(temp[i]);
count++;

if (count == k && i != 0) {
result.push_back('-');
count = 0;
}
}

// 3. Reverse the result string
reverse(result.begin(), result.end());

// 4. Print final output
cout << result << endl;

return 0;
}