Notes
Notes - notes.io |
#include<string.h>
struct Materias
{
char Nome[25];
double Preco;
};
void Imprimir(struct Materias c)
{
printf("%s", c.Nome);
printf(" %.2lfn", c.Preco);
}
int main()
{
double TotalDinheiro, SomaTotal = 0.0, aux, maior=0.0;
char Aux[25];
int QuantidadeProdutos, i, j,f;
scanf("%lf", &TotalDinheiro);
scanf("%d", &QuantidadeProdutos);
struct Materias Material[QuantidadeProdutos];
//ler os produtos
for (i=0; i<QuantidadeProdutos; i++)
{
scanf("%s", Material[i].Nome);
scanf("%lf", &Material[i].Preco);
SomaTotal += Material[i].Preco;
}
//ordenar do maior pro menor
for (i=1; i<QuantidadeProdutos; i++)
{
for (j=0; j<QuantidadeProdutos-i; j++)
{
if(strcmp(Material[j].Nome,Material[j+1].Nome)>0)
{
aux = Material[j].Preco;
Material[j].Preco = Material[j+1].Preco;
Material[j+1].Preco = aux;
strcpy(Aux,Material[j].Nome);
strcpy(Material[j].Nome,Material[j+1].Nome);
strcpy(Material[j+1].Nome,Aux);
}
}
}
//se a soma do produto for menor, n?o precisa fazer mais nada
if (SomaTotal<=TotalDinheiro)
{
for (i=0; i<QuantidadeProdutos; i++)
{
Imprimir(Material[i]);
}
printf("%.2lf", TotalDinheiro-SomaTotal);
}
else
{
for (i=0; i<QuantidadeProdutos; i++)
{
//olhar quem ? o maior e para ser subtraido o total e ver se vai d? para ele comprar tudo
for (f=QuantidadeProdutos-1; f>=0; f--)
{
if(Material[f].Preco>maior)
{
maior = Material[f].Preco;
j=f;
}
}
Material[j].Preco = 0.0;
SomaTotal-= maior;
if(SomaTotal<=TotalDinheiro)
{
for (j=0; j<QuantidadeProdutos; j++)
{
if(Material[j].Preco!=0.0)
{
Imprimir(Material[j]);
}
}
printf("%.2lf", TotalDinheiro-SomaTotal);
break;
}
}
}
return 0;
}
|
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team