Click here to Skip to main content
15,905,136 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: #include - again Pin
BernardIE531717-Apr-24 12:11
BernardIE531717-Apr-24 12:11 
GeneralRe: #include - again Pin
k505410-Apr-24 6:35
mvek505410-Apr-24 6:35 
GeneralRe: #include - again Pin
trønderen10-Apr-24 7:11
trønderen10-Apr-24 7:11 
QuestionForward declaration placement ? Pin
Salvatore Terress3-Apr-24 12:28
Salvatore Terress3-Apr-24 12:28 
AnswerRe: Forward declaration placement ? Pin
Greg Utas3-Apr-24 12:44
professionalGreg Utas3-Apr-24 12:44 
GeneralRe: Forward declaration placement ? Pin
Salvatore Terress3-Apr-24 13:14
Salvatore Terress3-Apr-24 13:14 
GeneralRe: Forward declaration placement ? Pin
Greg Utas3-Apr-24 14:05
professionalGreg Utas3-Apr-24 14:05 
QuestionC++ coding problem is failing for different test cases especially when input is 1. Please Help. Pin
priyanka mp1-Apr-24 22:39
priyanka mp1-Apr-24 22:39 
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 ?

C++
#include <bits/stdc++.h>
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<<reSize(s)<<endl;
	}
	return 0;
}


modified 2-Apr-24 6:37am.

AnswerRe: C++ coding problem is failing for different test cases especially when input is 1. Please Help. Pin
Pete O'Hanlon1-Apr-24 22:43
mvePete O'Hanlon1-Apr-24 22:43 
AnswerRe: C++ coding problem is failing for different test cases especially when input is 1. Please Help. Pin
Richard MacCutchan2-Apr-24 0:40
mveRichard MacCutchan2-Apr-24 0:40 
AnswerRe: C++ coding problem is failing for different test cases especially when input is 1. Please Help. Pin
Maximilien2-Apr-24 5:37
Maximilien2-Apr-24 5:37 
AnswerRe: C++ coding problem is failing for different test cases especially when input is 1. Please Help. Pin
CPallini2-Apr-24 8:49
mveCPallini2-Apr-24 8:49 
AnswerRe: C++ coding problem is failing for different test cases especially when input is 1. Please Help. Pin
jschell2-Apr-24 14:09
jschell2-Apr-24 14:09 
QuestionNecesito ayuda para un código para este programa -- I need help with a code for this program Pin
Member 1623306629-Mar-24 11:50
Member 1623306629-Mar-24 11:50 
AnswerRe: Necesito ayuda para un código para este programa -- I need help with a code for this program Pin
Richard Andrew x641-Apr-24 9:05
professionalRichard Andrew x641-Apr-24 9:05 
QuestionVariable types in ASM Pin
Calin Negru27-Mar-24 3:22
Calin Negru27-Mar-24 3:22 
AnswerRe: Variable types in ASM Pin
Maximilien27-Mar-24 3:49
Maximilien27-Mar-24 3:49 
AnswerRe: Variable types in ASM Pin
Mircea Neacsu27-Mar-24 3:59
Mircea Neacsu27-Mar-24 3:59 
GeneralRe: Variable types in ASM Pin
Richard MacCutchan27-Mar-24 4:02
mveRichard MacCutchan27-Mar-24 4:02 
AnswerRe: Variable types in ASM Pin
Richard MacCutchan27-Mar-24 4:01
mveRichard MacCutchan27-Mar-24 4:01 
GeneralRe: Variable types in ASM Pin
jeron127-Mar-24 4:52
jeron127-Mar-24 4:52 
GeneralRe: Variable types in ASM Pin
Calin Negru27-Mar-24 5:26
Calin Negru27-Mar-24 5:26 
GeneralRe: Variable types in ASM Pin
Richard MacCutchan27-Mar-24 6:09
mveRichard MacCutchan27-Mar-24 6:09 
AnswerRe: Variable types in ASM Pin
Calin Negru27-Mar-24 5:27
Calin Negru27-Mar-24 5:27 
Questioncommunication from library to application Pin
utcode21-Mar-24 16:23
utcode21-Mar-24 16:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.