Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void Withdraw(unsigned *v, unsigned *x, unsigned i) {
- if (*x / i <= *v)
- *v -= *x / i, *x %= i; // daca sunt mai baconte de de i de cat x
- else
- *x -= i * *v, *v = 0; // daca sunt mai putine baconte de i decat x (scoate toate bacontele ramase)
- }
- int main() {
- unsigned v[8], t, x, i;
- FILE *f, *g;
- f = fopen("atm.in", "r"); // deschidere mod citire
- g = fopen("atm.out", "w");
- for (i = 0; i < 8; i++) // citire numar de bacnote
- fscanf(f, "%u", &v[i]);
- fscanf(f, "%u", &t);
- for (i = 0; i < t; i++) {
- fscanf(f, "%u", &x);
- Withdraw(&v[7], &x, 500);
- Withdraw(&v[6], &x, 200);
- Withdraw(&v[5], &x, 100);
- Withdraw(&v[4], &x, 50);
- Withdraw(&v[3], &x, 20);
- Withdraw(&v[2], &x, 10);
- Withdraw(&v[1], &x, 5);
- Withdraw(&v[0], &x, 1);
- if (x) { //daca mai trebuie baconte retrase programul afiseaza si se opreste
- fprintf(g, "NU");
- fclose(f);
- fclose(g);
- return 0;
- }
- }
- fprintf(g, "DA");
- fclose(f);
- fclose(g);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment