Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.8 kB
2
Indexable
Never
#include<bits/stdc++.h>
using namespace std;
# define PI 3.14159265358979323846
int main()
{
	int A[10000];
    int B[10000];
    A[1]=0;
    A[2]=1;
    B[0]=2;
    int z=1;
    for(int i=3;i<10000;i++)
    {
        A[i]=0;
        int j=0;
        int ret=0;
        while(B[j]*B[j]<=i)
        {
            if(i%B[j]==0)
                ret++;
            j++;
        }
        if(ret==0)
        {
            B[z]=i;
            A[i]=1;
            z++;
        }
    }
	char x;
	int kinds=0;
	int money=0;
	int C[6];
	int D[6]={152,323,462,714,665,660};
	for(int i=0;i<6;i++)
		C[i]=0;
	int y;
	while(cin>>x)
	{
		if(x=='0')
			break;
		else 
		{
			cin>>y;
			if(x-'a'<=5&&x-'a'>=0)
			{
				C[(x-'a')]+=y;
				money+=y*D[x-'a'];
			}
		}
	}
	for(int i=0;i<6;i++)
	{
		if(C[i]>0)
			kinds++;
	}
	if(kinds==1)
	{
		for(int i=0;i<6;i++)
		{
			if(C[i]>0)
				money=C[i]*D[i];
		}
		int q=money;
		int discount=0;
		while(q>1)
		{
			for(int i=0;i<z;i++)
			{
				while(q%B[i]==0)
				{
					
					q=q/B[i];
					discount=discount+1+B[i];
				}
			}
		}
		cout<<"Total Amount: $"<<money<<'\n';
		cout<<"Discount Amount: $"<<discount<<'\n';
		cout<<"Price After Discount: $"<<money-discount;
	}
	else if(kinds>1)
	{
		int discount =0;
		for(int i=0;i<6;i++)
			D[i]*=C[i];
		int max=0,maax=0,d;
		for(int i=0;i<6;i++)
		{
			if(D[i]>max)
			{
				max=D[i];
				d=i;
			}
		}
		for(int i=0;i<6;i++)
		{
			if(D[i]>maax&&i!=d)
				maax=D[i];
		}
		int maaax;
		for(int i=1;i<=max;i++)
		{
			if((max%i==0)&&(maax%i==0))
				maaax=i;
		}
		discount = 200+kinds*maaax;
	cout<<"Total Amount: $"<<money<<'\n';
		cout<<"Discount Amount: $"<<discount<<'\n';
		cout<<"Price After Discount: $"<<money-discount;
	}
}