#include <iostream>
#include <string>
using namespace std;
float calculateCost(int duration, bool sameOperator) {
const int first30Rate = 3; // 3 den per minute for first 30 minutes
const int after30Rate = 2; // 2 den per minute after 30 minutes
float cost = 0;
if (duration <= 30) {
cost = duration * first30Rate;
} else {
cost = (30 * first30Rate) + ((duration - 30) * after30Rate);
}
// Apply 30% discount if both numbers are from the same operator
if (sameOperator) {
cost *= 0.7;
}
return cost;
}
bool sameOperator(const string &num1, const string &num2) {
// Assume numbers are from the same operator if first 3 digits match
return num1.substr(0, 3) == num2.substr(0, 3);
}
int main() {
string phoneNumber1, phoneNumber2;
int duration;
cout << "Enter the first phone number: ";
cin >> phoneNumber1;
cout << "Enter the second phone number: ";
cin >> phoneNumber2;
cout << "Enter the duration of the call (in minutes): ";
cin >> duration;
// Check if numbers are valid (9 digits and start with 0)
if (phoneNumber1.length() != 9 || phoneNumber1[0] != '0' ||
phoneNumber2.length() != 9 || phoneNumber2[0] != '0') {
cout << "Invalid phone number format." << endl;
return 1;
}
bool isSameOperator = sameOperator(phoneNumber1, phoneNumber2);
float cost = calculateCost(duration, isSameOperator);
cout << "The cost of the call is: " << cost << " den" << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmZsb2F0IGNhbGN1bGF0ZUNvc3QoaW50IGR1cmF0aW9uLCBib29sIHNhbWVPcGVyYXRvcikgewogICAgY29uc3QgaW50IGZpcnN0MzBSYXRlID0gMzsgLy8gMyBkZW4gcGVyIG1pbnV0ZSBmb3IgZmlyc3QgMzAgbWludXRlcwogICAgY29uc3QgaW50IGFmdGVyMzBSYXRlID0gMjsgLy8gMiBkZW4gcGVyIG1pbnV0ZSBhZnRlciAzMCBtaW51dGVzCiAgICBmbG9hdCBjb3N0ID0gMDsKCiAgICBpZiAoZHVyYXRpb24gPD0gMzApIHsKICAgICAgICBjb3N0ID0gZHVyYXRpb24gKiBmaXJzdDMwU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