< Back to forum

my program is having problem in comparison of string no and my integer no ...a,b variables are not updating ... link to question https://www.codechef.com/problems/CHEFPDIG

#include<bits/stdc++.h>
using namespace std;


int main()
{
int t;
cin>>t;

while(t--)
{
string s;
cin>>s;

int a,b,i,f,m,l,len;
char c;

for(c='A';c<='Z';c++)
{

a=0;
b=0;

int f = c / 10;
int l = c % 10;
len=s.length();

if(f!=l)
{

for(i=0;s[i]!='\0';i++)
{
  if(int(s[i])==f)
    a++;

  if(s[i]==l)
    b++;

}
if(a>=1&&b>=1)
  cout<<c<<endl;
}

else if(f==l)
{
    a=0;
for(i=0;i<len;i++)
{

  if(s[i]==f)
    a++;
}
}

 if(a>=2)
   cout<<c<<endl;

}
}


return 0;
}
 

Asked by: Manish_Kumar_Savita on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.


Enter your answer details below:


Enter your comment details below:




1 Answer(s)

avatar

check this line

//   if(int(s[i])==f)

you want to check the equality of the digits...but this statement is not doing the same

int ('6')  != 6

try to run this in your compiler

char ch =6;

cout<<int(ch);

use this fact and try again :)

Shubham_Gupta last updated on April 7, 2019, 6:34 p.m. 0    Reply    Upvote   

Instruction to write good question
  1. 1. Write a title that summarizes the specific problem
  2. 2. Pretend you're talking to a busy colleague
  3. 3. Spelling, grammar and punctuation are important!

Bad: C# Math Confusion
Good: Why does using float instead of int give me different results when all of my inputs are integers?
Bad: [php] session doubt
Good: How can I redirect users to different pages based on session data in PHP?
Bad: android if else problems
Good: Why does str == "value" evaluate to false when str is set to "value"?

Refer to Stack Overflow guide on asking a good question.