C++ coding problem is failing for different test cases especially when input is 1. Please Help.
-
Hi I have below code written while contesting on a platform, though I find working with code but it fails with different test cases especially when Input value is 1 and no string is provided. Can anyone please help to resolve this issue ?
#include
using namespace std;string reSize(string s)
{
if(s.length() > 0)
{
std::string res;
int count =1;
for(int i =0;i<(s.length() - 1);i++)
{
if(s[i] == s[i+1])
{
count++;
}
else
{
res += s[i];
if(count > 1)
{
res += std::to_string(count);
}
count = 1;
}
}res += s\[s.length() - 1\]; if(count > 1) { res += std::to\_string(count); } return res;
}
else if(s.empty())
{
return "";
}}
int main() {
int t;
cin>>t;
while(t--)
{
string s;
cin>>s;
cout< -
Hi I have below code written while contesting on a platform, though I find working with code but it fails with different test cases especially when Input value is 1 and no string is provided. Can anyone please help to resolve this issue ?
#include
using namespace std;string reSize(string s)
{
if(s.length() > 0)
{
std::string res;
int count =1;
for(int i =0;i<(s.length() - 1);i++)
{
if(s[i] == s[i+1])
{
count++;
}
else
{
res += s[i];
if(count > 1)
{
res += std::to_string(count);
}
count = 1;
}
}res += s\[s.length() - 1\]; if(count > 1) { res += std::to\_string(count); } return res;
}
else if(s.empty())
{
return "";
}}
int main() {
int t;
cin>>t;
while(t--)
{
string s;
cin>>s;
cout<What you need to do is put a breakpoint in your code, and step through it a line at a time. When you are executing a line, think about what you expect the outcome of that operation to be and compare what you think should be happening with what actually happens. Generally, this will lead you to work out what the problem actually is. There's a name for this type of approach, it's called debugging, and it's one of the most valuable skills you will ever learn.
-
Hi I have below code written while contesting on a platform, though I find working with code but it fails with different test cases especially when Input value is 1 and no string is provided. Can anyone please help to resolve this issue ?
#include
using namespace std;string reSize(string s)
{
if(s.length() > 0)
{
std::string res;
int count =1;
for(int i =0;i<(s.length() - 1);i++)
{
if(s[i] == s[i+1])
{
count++;
}
else
{
res += s[i];
if(count > 1)
{
res += std::to_string(count);
}
count = 1;
}
}res += s\[s.length() - 1\]; if(count > 1) { res += std::to\_string(count); } return res;
}
else if(s.empty())
{
return "";
}}
int main() {
int t;
cin>>t;
while(t--)
{
string s;
cin>>s;
cout< -
Hi I have below code written while contesting on a platform, though I find working with code but it fails with different test cases especially when Input value is 1 and no string is provided. Can anyone please help to resolve this issue ?
#include
using namespace std;string reSize(string s)
{
if(s.length() > 0)
{
std::string res;
int count =1;
for(int i =0;i<(s.length() - 1);i++)
{
if(s[i] == s[i+1])
{
count++;
}
else
{
res += s[i];
if(count > 1)
{
res += std::to_string(count);
}
count = 1;
}
}res += s\[s.length() - 1\]; if(count > 1) { res += std::to\_string(count); } return res;
}
else if(s.empty())
{
return "";
}}
int main() {
int t;
cin>>t;
while(t--)
{
string s;
cin>>s;
cout<what is this supposed to do ? what is the input and what is the output ? (what are the test cases ? )
CI/CD = Continuous Impediment/Continuous Despair
-
Hi I have below code written while contesting on a platform, though I find working with code but it fails with different test cases especially when Input value is 1 and no string is provided. Can anyone please help to resolve this issue ?
#include
using namespace std;string reSize(string s)
{
if(s.length() > 0)
{
std::string res;
int count =1;
for(int i =0;i<(s.length() - 1);i++)
{
if(s[i] == s[i+1])
{
count++;
}
else
{
res += s[i];
if(count > 1)
{
res += std::to_string(count);
}
count = 1;
}
}res += s\[s.length() - 1\]; if(count > 1) { res += std::to\_string(count); } return res;
}
else if(s.empty())
{
return "";
}}
int main() {
int t;
cin>>t;
while(t--)
{
string s;
cin>>s;
cout< -
Hi I have below code written while contesting on a platform, though I find working with code but it fails with different test cases especially when Input value is 1 and no string is provided. Can anyone please help to resolve this issue ?
#include
using namespace std;string reSize(string s)
{
if(s.length() > 0)
{
std::string res;
int count =1;
for(int i =0;i<(s.length() - 1);i++)
{
if(s[i] == s[i+1])
{
count++;
}
else
{
res += s[i];
if(count > 1)
{
res += std::to_string(count);
}
count = 1;
}
}res += s\[s.length() - 1\]; if(count > 1) { res += std::to\_string(count); } return res;
}
else if(s.empty())
{
return "";
}}
int main() {
int t;
cin>>t;
while(t--)
{
string s;
cin>>s;
cout<