Products – Total Price

There are four products ABC and D in a shop. The price of the four products are given below.
A – Rs.40 each or Rs.100 for a pack of 4
B – Rs.60 each
C – Rs.55 each or Rs.200 for a pack of 6
D – Rs.95 each
The program must accept a string S representing the products in a cart. The program must print the total price for the entire cart based on the given price list.

Boundary Condition(s):
1 <= Length of S <= 1000

Input Format:
The first line contains S.

Output Format:
The first line contains the total price for the entire cart based on the given price list.

Example Input/Output 1:
Input:
ABACDBAAA

Output:
410

Explanation:
A – quantity 5 – (100 + 40)
B – quantity 2 – (60 + 60)
C – quantity 1 – 55
D – quantity 1 – 95
Total price – 410

Example Input/Output 2:
Input:
CACCCDAADCCCCCCCBC

Output:
770

string=input()
lis=list(string)
countOfA=lis.count('A')
countOfC=lis.count('C')

price=0
price+=lis.count('B')*60
price+=lis.count('D')*95

price+=(countOfA//4*100)+(countOfA%4*40)
price+=(countOfC//6*200)+(countOfC%6*55)
print(price)
#include<stdio.h>
#include<stdlib.h>

int main()
{
    int Ac=0,Bc=0,Cc=0,Dc=0;
    char str[1000];
    scanf("%s",str);
    for(int i=0;str[i]!='';i++){
        if(str[i]=='A') Ac++;
        else if(str[i]=='B') Bc++;
        else if(str[i]=='C') Cc++;
        else Dc++;
    }
    Ac=(Ac/4)*100+(Ac%4)*40;
    Bc=Bc*60;
    Cc=(Cc/6)*200+(Cc%6)*55;
    Dc=Dc*95;
    printf("%d",Ac+Bc+Cc+Dc);
}
import java.util.*;
public class Hello {

    public static void main(String[] args) {
//Your Code Here
Scanner sc=new Scanner(System.in);
String a=sc.nextLine();
int sum=0,counta=0,countc=0;
for(int i=0;i<a.length();i++)
{
    if(a.charAt(i)=='A')
       counta+=1;
    else if(a.charAt(i)=='B')
        sum+=60;
    else if(a.charAt(i)=='C')
         countc+=1;
    else
    sum+=95;
}
if(counta>=4)
{
    sum+=((counta/4)*100)+((counta%4)*40);
}
else
{
   sum+=counta*40;
}
if(countc>=6)
{
    sum+=((countc/6)*200)+((countc%6)*55);
}
else
{
    sum+=countc*55;
}
System.out.println(sum);

}
}
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char** argv)
{
    ios_base::sync_with_stdio(false);
    string s;
    cin>>s;
    int a=0,b=0,c=0,d=0,ans;
    for(int i=0;i<s.length();i++){
        if(s[i]=='A'){
            a++;
        }else if(s[i]=='B'){
            b++;
        }else if(s[i]=='C'){
            c++;
        }else{
            d++;
        }
    }
    ans=((a/4)*100)+((c/6)*200)+((a%4)*40)+(b*60)+((c%6)*55)+(d*95);
    cout<<ans;
}
Previous Article

function findNextWordPosition

Next Article

Form Integers - Divisible by 25

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *