Detalii evaluare #16692539

Rezumat problemă

Se consideră un text memorat într-o matrice M, definită prin coordonatele colţului stânga sus (x1,y1) şi coordonatele colţului dreapta jos (x2,y2).

Prin aplicarea unui algoritm de compresie, matricei M i se asociază un şir de caractere, notat CM. Şirul de caractere CM este construit prin aplicarea următoarelor reguli:

  1. dacă matricea M are o singură linie şi o singură coloană atunci CM conţine numai caracterul memorat în matrice;
  2. dacă toate elementele matricei sunt identice atunci întreaga matrice M se comprimă şi CM este şirul kc, unde k reprezintă numărul de caractere din matrice, iar c caracterul memorat;
  3. dacă matricea este formată din caractere diferite şi are cel puţin două linii şi două coloane atunci:
    • matricea este împărţită în 4 submatrice A, B, C, D după cum este ilustrat în figura alăturată, unde coordonatele colţului stânga sus ale submatricei A sunt (x1,y1), iar coordonatele colţului dreapta jos sunt ((x2+x1)/2,(y2+y1)/2);
    • CM este şirul *CACBCCCD unde CA, CB, CC, CD sunt şirurile de caractere obţinute, în ordine, prin compresia matricelor A, B, C, D utilizând acelaşi algoritm;
  4. dacă matricea este formată din caractere diferite, are o singură linie şi mai multe coloane atunci CM este şirul *CACB unde A, B, CA, CB au semnificaţia descrisă la punctul 3.;
  5. dacă matricea este formată din caractere diferite, are mai multe linii şi o singură coloană atunci CM este şirul *CACC unde A, C, CA, CC au semnificaţia descrisă la punctul 3.;

Dat fiind şirul de caractere CM ce se obţine în urma aplicării algoritmului de compresie asupra unei matrice M de dimensiune NxN să se determine:

  1. numărul de împărţiri care au fost necesare pentru obţinerea textului compresat;
  2. matricea iniţială din care provine textul compresat.

Detalii

Problema Compresie Operații I/O compresie.in/compresie.out
Limita timp 0.5 secunde Limita memorie Total: 4 MB / Stivă 3 MB
Id soluție #16692539 Utilizator Cioara David (david_darius)
Fișier compresie.cpp Dimensiune 1.62 KB
Data încărcării 16 Septembrie 2019, 19:40 Scor / rezultat Eroare de compilare

Evaluare


Mesaj compilare

compresie.cpp:7:27: error: 'long long int index' redeclared as different kind of symbol
 long long nrCompresii,dim,index;

                           ^
In file included from /usr/include/c++/4.8/cstring:42:0,
                 from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:48,
                 from compresie.cpp:1:
/usr/include/string.h:482:1: error: previous declaration of 'const char* index(const char*, int)'
 index (const char *__s, int __c) __THROW
 ^
compresie.cpp: In function 'void matrice(int, int, int, int)':
compresie.cpp:26:13: error: no match for 'operator[]' (operand types are 'std::string {aka std::basic_string<char>}' and '<unresolved overloaded function type>')
         if(s[index]=='*'){

             ^
compresie.cpp:26:13: note: candidates are:
In file included from /usr/include/c++/4.8/string:52:0,
                 from /usr/include/c++/4.8/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8/bits/ios_base.h:41,
                 from /usr/include/c++/4.8/ios:42,
                 from /usr/include/c++/4.8/istream:38,
                 from /usr/include/c++/4.8/sstream:38,
                 from /usr/include/c++/4.8/complex:45,
                 from /usr/include/c++/4.8/ccomplex:38,
                 from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:52,
                 from compresie.cpp:1:
/usr/include/c++/4.8/bits/basic_string.h:826:7: note: std::basic_string<_CharT, _Traits, _Alloc>::const_reference std::basic_string<_CharT, _Traits, _Alloc>::operator[](std::basic_string<_CharT, _Traits, _Alloc>::size_type) const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits, _Alloc>::const_reference = const char&; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
       operator[] (size_type __pos) const
       ^
/usr/include/c++/4.8/bits/basic_string.h:826:7: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::basic_string<char>::size_type {aka unsigned int}'
/usr/include/c++/4.8/bits/basic_string.h:843:7: note: std::basic_string<_CharT, _Traits, _Alloc>::reference std::basic_string<_CharT, _Traits, _Alloc>::operator[](std::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits, _Alloc>::reference = char&; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
       operator[](size_type __pos)
       ^
/usr/include/c++/4.8/bits/basic_string.h:843:7: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::basic_string<char>::size_type {aka unsigned int}'
compresie.cpp:27:15: error: no pre-increment operator for type
             ++index;

               ^
compresie.cpp:35:18: error: no match for 'operator[]' (operand types are 'std::string {aka std::basic_string<char>}' and '<unresolved overloaded function type>')
         else if(s[index]>='a' && s[index]<='z'){

                  ^
compresie.cpp:35:18: note: candidates are:
In file included from /usr/include/c++/4.8/string:52:0,
                 from /usr/include/c++/4.8/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8/bits/ios_base.h:41,
                 from /usr/include/c++/4.8/ios:42,
                 from /usr/include/c++/4.8/istream:38,
                 from /usr/include/c++/4.8/sstream:38,
                 from /usr/include/c++/4.8/complex:45,
                 from /usr/include/c++/4.8/ccomplex:38,
                 from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:52,
                 from compresie.cpp:1:
/usr/include/c++/4.8/bits/basic_string.h:826:7: note: std::basic_string<_CharT, _Traits, _Alloc>::const_reference std::basic_string<_CharT, _Traits, _Alloc>::operator[](std::basic_string<_CharT, _Traits, _Alloc>::size_type) const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits, _Alloc>::const_reference = const char&; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
       operator[] (size_type __pos) const
       ^
/usr/include/c++/4.8/bits/basic_string.h:826:7: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::basic_string<char>::size_type {aka unsigned int}'
/usr/include/c++/4.8/bits/basic_string.h:843:7: note: std::basic_string<_CharT, _Traits, _Alloc>::reference std::basic_string<_CharT, _Traits, _Alloc>::operator[](std::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits, _Alloc>::reference = char&; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
       operator[](size_type __pos)
       ^
/usr/include/c++/4.8/bits/basic_string.h:843:7: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::basic_string<char>::size_type {aka unsigned int}'
compresie.cpp:35:35: error: no match for 'operator[]' (operand types are 'std::string {aka std::basic_string<char>}' and '<unresolved overloaded function type>')
         else if(s[index]>='a' && s[index]<='z'){

                                   ^
compresie.cpp:35:35: note: candidates are:
In file included from /usr/include/c++/4.8/string:52:0,
                 from /usr/include/c++/4.8/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8/bits/ios_base.h:41,
                 from /usr/include/c++/4.8/ios:42,
                 from /usr/include/c++/4.8/istream:38,
                 from /usr/include/c++/4.8/sstream:38,
                 from /usr/include/c++/4.8/complex:45,
                 from /usr/include/c++/4.8/ccomplex:38,
                 from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:52,
                 from compresie.cpp:1:
/usr/include/c++/4.8/bits/basic_string.h:826:7: note: std::basic_string<_CharT, _Traits, _Alloc>::const_reference std::basic_string<_CharT, _Traits, _Alloc>::operator[](std::basic_string<_CharT, _Traits, _Alloc>::size_type) const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits, _Alloc>::const_reference = const char&; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
       operator[] (size_type __pos) const
       ^
/usr/include/c++/4.8/bits/basic_string.h:826:7: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::basic_string<char>::size_type {aka unsigned int}'
/usr/include/c++/4.8/bits/basic_string.h:843:7: note: std::basic_string<_CharT, _Traits, _Alloc>::reference std::basic_string<_CharT, _Traits, _Alloc>::operator[](std::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits, _Alloc>::reference = char&; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
       operator[](size_type __pos)
       ^
/usr/include/c++/4.8/bits/basic_string.h:843:7: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::basic_string<char>::size_type {aka unsigned int}'
compresie.cpp:36:26: error: no match for 'operator[]' (operand types are 'std::string {aka std::basic_string<char>}' and '<unresolved overloaded function type>')
             a[i1][j1] = s[index];

                          ^
compresie.cpp:36:26: note: candidates are:
In file included from /usr/include/c++/4.8/string:52:0,
                 from /usr/include/c++/4.8/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8/bits/ios_base.h:41,
                 from /usr/include/c++/4.8/ios:42,
                 from /usr/include/c++/4.8/istream:38,
                 from /usr/include/c++/4.8/sstream:38,
                 from /usr/include/c++/4.8/complex:45,
                 from /usr/include/c++/4.8/ccomplex:38,
                 from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:52,
                 from compresie.cpp:1:
/usr/include/c++/4.8/bits/basic_string.h:826:7: note: std::basic_string<_CharT, _Traits, _Alloc>::const_reference std::basic_string<_CharT, _Traits, _Alloc>::operator[](std::basic_string<_CharT, _Traits, _Alloc>::size_type) const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits, _Alloc>::const_reference = const char&; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
       operator[] (size_type __pos) const
       ^
/usr/include/c++/4.8/bits/basic_string.h:826:7: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::basic_string<char>::size_type {aka unsigned int}'
/usr/include/c++/4.8/bits/basic_string.h:843:7: note: std::basic_string<_CharT, _Traits, _Alloc>::reference std::basic_string<_CharT, _Traits, _Alloc>::operator[](std::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits, _Alloc>::reference = char&; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
       operator[](size_type __pos)
       ^
/usr/include/c++/4.8/bits/basic_string.h:843:7: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::basic_string<char>::size_type {aka unsigned int}'
compresie.cpp:37:15: error: no pre-increment operator for type
             ++index;

               ^
compresie.cpp:43:20: error: no match for 'operator[]' (operand types are 'std::string {aka std::basic_string<char>}' and '<unresolved overloaded function type>')
             while(s[index]>='0' && s[index]<='9'){++index;}

                    ^
compresie.cpp:43:20: note: candidates are:
In file included from /usr/include/c++/4.8/string:52:0,
                 from /usr/include/c++/4.8/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8/bits/ios_base.h:41,
                 from /usr/include/c++/4.8/ios:42,
                 from /usr/include/c++/4.8/istream:38,
                 from /usr/include/c++/4.8/sstream:38,
                 from /usr/include/c++/4.8/complex:45,
                 from /usr/include/c++/4.8/ccomplex:38,
                 from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:52,
                 from compresie.cpp:1:
/usr/include/c++/4.8/bits/basic_string.h:826:7: note: std::basic_string<_CharT, _Traits, _Alloc>::const_reference std::basic_string<_CharT, _Traits, _Alloc>::operator[](std::basic_string<_CharT, _Traits, _Alloc>::size_type) const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits, _Alloc>::const_reference = const char&; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
       operator[] (size_type __pos) const
       ^
/usr/include/c++/4.8/bits/basic_string.h:826:7: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::basic_string<char>::size_type {aka unsigned int}'
/usr/include/c++/4.8/bits/basic_string.h:843:7: note: std::basic_string<_CharT, _Traits, _Alloc>::reference std::basic_string<_CharT, _Traits, _Alloc>::operator[](std::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits, _Alloc>::reference = char&; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
       operator[](size_type __pos)
       ^
/usr/include/c++/4.8/bits/basic_string.h:843:7: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::basic_string<char>::size_type {aka unsigned int}'
compresie.cpp:43:37: error: no match for 'operator[]' (operand types are 'std::string {aka std::basic_string<char>}' and '<unresolved overloaded function type>')
             while(s[index]>='0' && s[index]<='9'){++index;}

                                     ^
compresie.cpp:43:37: note: candidates are:
In file included from /usr/include/c++/4.8/string:52:0,
                 from /usr/include/c++/4.8/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8/bits/ios_base.h:41,
                 from /usr/include/c++/4.8/ios:42,
                 from /usr/include/c++/4.8/istream:38,
                 from /usr/include/c++/4.8/sstream:38,
                 from /usr/include/c++/4.8/complex:45,
                 from /usr/include/c++/4.8/ccomplex:38,
                 from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:52,
                 from compresie.cpp:1:
/usr/include/c++/4.8/bits/basic_string.h:826:7: note: std::basic_string<_CharT, _Traits, _Alloc>::const_reference std::basic_string<_CharT, _Traits, _Alloc>::operator[](std::basic_string<_CharT, _Traits, _Alloc>::size_type) const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits, _Alloc>::const_reference = const char&; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
       operator[] (size_type __pos) const
       ^
/usr/include/c++/4.8/bits/basic_string.h:826:7: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::basic_string<char>::size_type {aka unsigned int}'
/usr/include/c++/4.8/bits/basic_string.h:843:7: note: std::basic_string<_CharT, _Traits, _Alloc>::reference std::basic_string<_CharT, _Traits, _Alloc>::operator[](std::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits, _Alloc>::reference = char&; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
       operator[](size_type __pos)
       ^
/usr/include/c++/4.8/bits/basic_string.h:843:7: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::basic_string<char>::size_type {aka unsigned int}'
compresie.cpp:43:53: error: no pre-increment operator for type
             while(s[index]>='0' && s[index]<='9'){++index;}

                                                     ^
compresie.cpp:46:32: error: no match for 'operator[]' (operand types are 'std::string {aka std::basic_string<char>}' and '<unresolved overloaded function type>')
                     a[x][y] = s[index];

                                ^
compresie.cpp:46:32: note: candidates are:
In file included from /usr/include/c++/4.8/string:52:0,
                 from /usr/include/c++/4.8/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8/bits/ios_base.h:41,
                 from /usr/include/c++/4.8/ios:42,
                 from /usr/include/c++/4.8/istream:38,
                 from /usr/include/c++/4.8/sstream:38,
                 from /usr/include/c++/4.8/complex:45,
                 from /usr/include/c++/4.8/ccomplex:38,
                 from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:52,
                 from compresie.cpp:1:
/usr/include/c++/4.8/bits/basic_string.h:826:7: note: std::basic_string<_CharT, _Traits, _Alloc>::const_reference std::basic_string<_CharT, _Traits, _Alloc>::operator[](std::basic_string<_CharT, _Traits, _Alloc>::size_type) const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits, _Alloc>::const_reference = const char&; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
       operator[] (size_type __pos) const
       ^
/usr/include/c++/4.8/bits/basic_string.h:826:7: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::basic_string<char>::size_type {aka unsigned int}'
/usr/include/c++/4.8/bits/basic_string.h:843:7: note: std::basic_string<_CharT, _Traits, _Alloc>::reference std::basic_string<_CharT, _Traits, _Alloc>::operator[](std::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits, _Alloc>::reference = char&; std::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]
       operator[](size_type __pos)
       ^
/usr/include/c++/4.8/bits/basic_string.h:843:7: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::basic_string<char>::size_type {aka unsigned int}'
compresie.cpp:49:15: error: no pre-increment operator for type
             ++index;

               ^
compresie.cpp:24:13: warning: unused variable 'nr' [-Wunused-variable]
     int x,y,nr;

             ^

Cum funcționează evaluarea?

www.pbinfo.ro permite evaluarea a două tipuri de probleme:

  • probleme la care rezolvarea presupune scrierea unui program complet
  • probleme la care rezolvarea presupune scrierea unei secvențe de program - câteva instrucțiuni, o listă de declarații, una sau mai multe funcții, etc.

Problema Compresie face parte din prima categorie. Soluția propusă de tine va fi evaluată astfel:

  • Programul sursă este compilat folosind compilatorul corespunzător. Dacă în urma compilării se obțin erori sau avertismente, acestea sunt afișate în această pagină.
  • Dacă programul a fost compilat, executabilul obținut va fi rulat, furnizându-i-se unul sau mai multe seturi de date de intrare, în concordanță cu restricțiile specifice problemei. Pentru fiecare set de date se obține un anumit punctaj, în raport cu corectitudinea soluției tale.

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ă.