Well, that proves nothing. All it shows is that you havenât found the problem yet.
Compile this
using namespace std;
int main() {
char ok[6]=âhelloâ;
char bad[5]=âhelloâ;
return 0;
}
On ideone.com, using the C++ 4.3.2, it reports
Compilation error #stdin compilation error #stdout 0s 0KB
prog.cpp: In function âint main()â:
prog.cpp:5:14: error: initializer-string for array of chars is too long [-fpermissive]
char bad[5]=âhelloâ;
^~~~~~~
Then try this:
#include < cstring >
#include < iostream >
using namespace std;
int main() {
char a[2];
char b[11]=âabcdefghijâ;
strcpy(a,b);
cout << a << â\nâ;
return 0;
}
You can see itâs definitely wrong right? Yet it works.
Having this sort of thing is a recipe for disaster. See buffer overflow.
.
Anyway, try this test case:
58 46
1 22 3 4 5 12 2 34 12 43 32 23 52 23 54 97 55 74 34 36 38 29 10 38 28 10
wgnjejghiopfjgpiojmvgkfnhsetjiohgiokbmsdgklnmjosjgsopdfivj
vnaklngviowjpfaienmzsxcmzlbvziopjpowiuerqptjut
Spoj toolkit suggests answer should be 695.