#4298
Victor și tatăl său au mers la magazinul de bomboane pentru ca tatăl să își onoreze o mai veche promisiune. Magazinul are bomboanele aranjate pe un rând, în mai multe cutii așezate una lângă alta. Se cunoaște numărul de bomboane din fiecare cutie, în ordinea în care sunt așezate cutiile începând de la intrare.
Tatăl i-a fixat lui Victor următoarea regulă de colectare a bomboanelor:
Determinați câte bomboane a colectat Victor.
CPPI Craiova - Concurs de antrenament 4-5 ianuarie 2023
| Problema | lacom | Operații I/O |
lacom.in/lacom.out
|
|---|---|---|---|
| Limita timp | 0.1 secunde | Limita memorie |
Total: 64 MB
/
Stivă 8 MB
|
| Id soluție | #62620217 | Utilizator | |
| Fișier | lacom.c | Dimensiune | 512 B |
| Data încărcării | 27 Ianuarie 2026, 20:10 | Scor/rezultat | Eroare de compilare |
lacom.c: In function 'main': lacom.c:5:24: warning: character constant too long for its type [enabled by default] char file_name_in[] = 'lacom.in'; ^ lacom.c:5:2: error: invalid initializer char file_name_in[] = 'lacom.in'; ^ lacom.c:6:28: warning: character constant too long for its type [enabled by default] char file_name_out[] = 'lacom.out'; ^ lacom.c:6:5: error: invalid initializer char file_name_out[] = 'lacom.out'; ^ lacom.c:7:22: error: expected expression before 'const' FILE *in = fopen(const char file_name_in, "rt"); ^ lacom.c:7:22: error: too few arguments to function 'fopen' In file included from lacom.c:1:0: /usr/include/stdio.h:272:14: note: declared here extern FILE *fopen (const char *__restrict __filename, ^ lacom.c:7:16: warning: initialization from incompatible pointer type [enabled by default] FILE *in = fopen(const char file_name_in, "rt"); ^ lacom.c:8:5: warning: passing argument 1 of 'fscanf' from incompatible pointer type [enabled by default] int n = fscanf("%d", &n); ^ In file included from /usr/include/features.h:374:0, from /usr/include/stdio.h:27, from lacom.c:1: /usr/include/stdio.h:443:12: note: expected 'struct FILE * restrict' but argument is of type 'char *' extern int __REDIRECT (fscanf, (FILE *__restrict __stream, ^ lacom.c:8:5: warning: passing argument 2 of 'fscanf' from incompatible pointer type [enabled by default] int n = fscanf("%d", &n); ^ In file included from /usr/include/features.h:374:0, from /usr/include/stdio.h:27, from lacom.c:1: /usr/include/stdio.h:443:12: note: expected 'const char * restrict' but argument is of type 'int *' extern int __REDIRECT (fscanf, (FILE *__restrict __stream, ^ lacom.c:8:5: warning: format not a string literal and no format arguments [-Wformat-security] int n = fscanf("%d", &n); ^ lacom.c:11:9: warning: passing argument 1 of 'fscanf' from incompatible pointer type [enabled by default] int nr = fscanf("%d", &nr); ^ In file included from /usr/include/features.h:374:0, from /usr/include/stdio.h:27, from lacom.c:1: /usr/include/stdio.h:443:12: note: expected 'struct FILE * restrict' but argument is of type 'char *' extern int __REDIRECT (fscanf, (FILE *__restrict __stream, ^ lacom.c:11:9: warning: passing argument 2 of 'fscanf' from incompatible pointer type [enabled by default] int nr = fscanf("%d", &nr); ^ In file included from /usr/include/features.h:374:0, from /usr/include/stdio.h:27, from lacom.c:1: /usr/include/stdio.h:443:12: note: expected 'const char * restrict' but argument is of type 'int *' extern int __REDIRECT (fscanf, (FILE *__restrict __stream, ^ lacom.c:11:9: warning: format not a string literal and no format arguments [-Wformat-security] int nr = fscanf("%d", &nr); ^ lacom.c:13:13: error: 'sum' undeclared (first use in this function) sum += nr; ^ lacom.c:13:13: note: each undeclared identifier is reported only once for each function it appears in lacom.c:13:13: warning: statement with no effect [-Wunused-value] lacom.c:17:23: error: expected expression before 'const' FILE *out = fopen(const char file_name_out, "wt"); ^ lacom.c:17:23: error: too few arguments to function 'fopen' In file included from lacom.c:1:0: /usr/include/stdio.h:272:14: note: declared here extern FILE *fopen (const char *__restrict __filename, ^ lacom.c:17:17: warning: initialization from incompatible pointer type [enabled by default] FILE *out = fopen(const char file_name_out, "wt"); ^ lacom.c:18:5: warning: passing argument 1 of 'fprintf' from incompatible pointer type [enabled by default] fprintf("%d", sum); ^ In file included from /usr/include/stdio.h:937:0, from lacom.c:1: /usr/include/i386-linux-gnu/bits/stdio2.h:95:1: note: expected 'struct FILE * restrict' but argument is of type 'char *' fprintf (FILE *__restrict __stream, const char *__restrict __fmt, ...) ^ lacom.c:18:5: warning: format not a string literal and no format arguments [-Wformat-security] fprintf("%d", sum); ^ lacom.c:6:10: warning: unused variable 'file_name_out' [-Wunused-variable] char file_name_out[] = 'lacom.out'; ^ lacom.c:5:7: warning: unused variable 'file_name_in' [-Wunused-variable] char file_name_in[] = 'lacom.in'; ^
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema lacom face parte din prima categorie. Soluția propusă de tine va fi evaluată astfel:
Suma punctajelor acordate pe testele utilizate pentru verificare este 100. Astfel, soluția ta poate obține cel mult 100 de puncte, caz în care se poate considera corectă.