// you can use includes, for example:
#include <algorithm>
#include <iostream>
#include <vector>
#include <iterator>
#include <ctype.h>
usingnamespace std;
// you can write to stdout for debugging purposes, e.g.
// printf("this is a debug message\n");
// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(string &S) {
int sol = -1;
bool flag = false;
int count = 0;
int maxcount = -1;
for (int i = 0; i< S.length(); i++){
int letter = S[i];
cout << "letter is " << letter << endl;
cout << "count is" << count << endl;
//if (isdigit(letter)){
if (48 <=letter <= 57){
count = 0;
}
//else if (isupper(letter)){
elseif (65 <= letter <=90){
flag = true;
count++;
}
//else if (islower(letter)){
elseif (97 <= letter <= 122){
count++;
}
if (count>maxcount){
maxcount = count;
}
}
if (flag) sol = maxcount;
return sol;
}
int main(){
string temp = "a0Ab";
int i = solution(temp);
cout << "The answer is: " << i << endl;
cin.clear();
getchar();
return 0;
}
When I remove the commented lines of code it works. I want the char to integer conversion part to work too.
I think I figured it out. I should have done if(48<=letter && letter<=57). It is same thing as not having (A == B==C) check in C++. Thanks @admkrk.
@CodeWriter: int solution is a subroutine to return if the input string has a upper case letter or not. It was part of coding challenge I failed to complete online.