I think I may have a solution to subsequence.
Code:
Please try to shoot this down with test cases. Thanks
temp2 eliminates recurring letters making temp increase too many times. If you were to run the second for loop for the string "lol"(longstr can be "loel" or something), it would increment temp twice, because j is starting from 0 every time, instead of the letter it used last.
Code:
Code:
// Returns true if shortstr is a subsequence of longstr,
// and false otherwise.
int subsequence(char shortstr[], char longstr[])
{
temp = 0;
int temp2 = 0;
for (i = 0; i < strlen(shortstr); i++)
{
for (j = temp2; j < strlen(longstr); j++)
{
printf("%c == %c %d %d\
\
", shortstr[i], longstr[j], temp, temp2);
if (shortstr[i] == longstr[j])
{
temp++;
temp2 = j+1;
break;
}
}
}
if (temp == strlen(shortstr)) return 1;
else return 0;
}

temp2 eliminates recurring letters making temp increase too many times. If you were to run the second for loop for the string "lol"(longstr can be "loel" or something), it would increment temp twice, because j is starting from 0 every time, instead of the letter it used last.