# Why my logic is wrong?

solution:

for _ in range(int(input())):
s=input().strip()
s+='*'
c=1
s1=''
for i in range(len(s)-1):
if s[i]==s[i+1]:
c+=1
else:
if c>=2:
s1+=s[i]+str(c)
else:
s1+=s[i]
c=1
sum1=0
sum2=0
#print(s,s1)
for i in range(len(s1)):
if s1[i].isalpha():
sum1+=1
else:
sum2+=1
newstr=(sum1*8)+(sum2*32)
#print(sum1,sum2)
sum3=0
sum4=0
for i in range(len(s)-1):
if s[i].isalpha():
sum3+=1
else:
sum4+=1
#print(sum3,sum4)
oldstr=(sum3*8)+(sum4*32)
#print(newstr,oldstr)
print(oldstr-newstr)

Mine too:

#include <bits/stdc++.h>

using namespace std;

int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
string s;
cin >> s;
long long a = 0, b = 0;
for (int i = 0; i < s.size(); ++i)
{
if ((int)s[i] >= 97) a += 8;
else a += 32;
}
char prev = '.';
int size = 0;
for (int i = 0; i < s.size(); ++i)
{
if (prev == '.')
{
prev = s[i];
++size;
} else {
if (s[i] == prev) ++size;
else {
if ((int)prev >= 97) b += 8;
else b += 32;
if (size > 1) b += ((floor(log10(size)) + 1)*32);
prev = '.';
--i;
size = 0;
}
}
if (i == s.size()-1)
{
if ((int)prev >= 97) b += 8;
else b += 32;
if (size > 1) b += ((floor(log10(size)) + 1)*32);
}
}
cout << (a-b) << '\n';
}
}

in sum2 variable you are counting digits, not integers. So if you have something like â€śa12â€ť your sum2 is 2 but 12 is just one integer, not two.

what is the size of the compress string of â€śaaaaaaaaaaaaâ€ť? I would say it is 8 + 32 = 40. Another interpretations is that it is 8 + 32 + 32 = 72.

1 Like

Itâ€™s totally understandable if you canâ€™t help. Not trynna be rude or anything but please stop shitposting in the forums. I was very serious and didnâ€™t know what I did wrong.
Thank you.

i think you did the same mistake as mineâ€¦you are adding 32 for every numeric digitâ€¦for eg: a987
sum would be 8+32 not 8+32+32+32â€¦

1 Like

Thanks a lot! Iâ€™m pretty sure this should get 100 AC but itâ€™s only getting 40

#include <bits/stdc++.h>

using namespace std;

int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
string s, res = "";
cin >> s;
long long a = 0, b = 0;
string ns = s;
for (int i = 0; i < ns.size(); ++i) if ((int)ns[i] > 58) ns[i] = '0'; else ns[i] = '1';
char preva = '.';
int sizea = 0;
for (int i = 0; i < ns.size(); ++i)
{
if (preva == '.')
{
preva = ns[i];
++sizea;
} else {
if (ns[i] == preva) ++sizea;
else {
if (preva == '0') a += (sizea*8);
else a += 32;
preva = '.';
--i;
sizea = 0;
}
}
if (i == ns.size()-1)
{
if (preva == '0') a += (sizea*8);
else a += 32;
}
}
char prev = '.';
int size = 0;
for (int i = 0; i < s.size(); ++i)
{
if (prev == '.')
{
prev = s[i];
++size;
} else {
if (s[i] == prev) ++size;
else {
string sn;
sn = (char)prev;
res.append(sn);
if (size > 1) res.append(to_string(size));
prev = '.';
--i;
size = 0;
}
}
if (i == s.size()-1)
{
string sn;
sn = (char)prev;
res.append(sn);
if (size > 1) res.append(to_string(size));
}
}
for (int i = 0; i < res.size(); ++i) if ((int)res[i] > 58) res[i] = '0'; else res[i] = '1';
char nprev = '.';
int nsize = 0;
for (int i = 0; i < res.size(); ++i)
{
if (nprev == '.')
{
nprev = res[i];
++nsize;
} else {
if (res[i] == nprev) ++nsize;
else {
if (nprev == '0') b += (nsize*8);
else b += 32;
nprev = '.';
--i;
nsize = 0;
}
}
if (i == res.size()-1)
{
if (nprev == '0') b += (nsize*8);
else b += 32;
}
}
cout << a-b << '\n';
}
}

I know my code is sorta unreadable and has a lot of poor variable names because I was in a hurry.
But I donâ€™t know for what case it fails to get 100.

The digits of the original string must be interpreted as characters (8 bits). And the integers counting the number or repetitions of each character in the compress string must be interpreted as integers (32 bits).

https://www.codechef.com/submit/complete/33633185

sorry