C++ :: Given A String How To Find Longest Substring With All Unique Characters

Feb 9, 2015

I am new to C++ programming, writing a program for the below question:

given a string, how to find the longest substring with all unique characters.

View 1 Replies


ADVERTISEMENT

C++ :: Find Substring From A String

Apr 23, 2012

I am stuck in some logic and want to write a program to do following tasks : I have three string variables to be compared to each other,a string having sub string & hierarchy string!!

1.) name1=john name2=tom_john_tom name3=alextom_john
thus we need to search john from name2 and name3 and if name1 exists in both name2 and name3 then ok else check for step2

2.) name1=a.b.c.d ,name2=a.b.c.d and name3=a.b.c.d
we need to compare each string seperated by a dot in all three variables and we need to match each string seperated by a delimeter "."
if name1.a==name2.a==name3.a and name1.b==name2.b==name3.b ,name1.c==name2.c==name3.c and name1.d==name2.d==name3.d then its a match
else its a mismatch

Also,the catch is we can have name1 ,name2 and name3 in format name1=*.*.*.* and name2=*.*.*.* and name3=*.*.*.*
where * defines it can be any value to be matched

name1=government.india.public.property
name2=rural.roads.maximum.x
name3=government.india.public.sales
name4=rural.roads.minumum.x

If operator wants to match only the second field , then the logic should be like:

If the Value is to be matched = (*.#.*.*)
then "matched"
Else
its a mismacth

# => for this field of name2 and name3 shall be same
* => for this field name2 and name3 shall be ignored for comparison

to obtain option1 we can have find function and substr however pls suggest how to approach for second option !!!!

View 1 Replies View Related

C/C++ :: Find Last Longest Word In A String

Apr 29, 2015

How to find the last longest word in a string when there are more of them (with the longest size)?

Here is the program for the longest without checking if last:

#include<stdio.h>
#include<string.h>
int main() {
char a[50],b[20],c[20];
int i,j=0,l=0;
printf("Enter a string:
");
gets(a);

[Code] ....

View 6 Replies View Related

C++ :: Finding If String Has Unique Characters

Mar 28, 2013

bool isUnique(string _str)
{
bool char_set[256];
int len = _str.length();
memset(char_set, '/0', 256);
for(int i = 0; i < len; ++i)

[Code] .....

I came across this code to find if string has unique characters...i didnt understand why they subracted ascii value of character '0' in the statement int val = _str[i]- '0' and what is happening with the statements...

if(char_set[val])
{
return false;
}
char_set[val] = true;

I take each character in the sting and traverse the whole string .and if count is 2 i use break and conclude that its not unique and not otherwise...can i use this method or this is not efficient????

View 8 Replies View Related

C/C++ :: Find The Common Characters Between Two String Characters

Jul 6, 2014

Im supposed to find the common characters between two string characters, assuming that the user wont input duplicate letters like ddog. When I run my code I get an output of a question mark upside down. Here is my code with comments on what each part is supposed to do

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char str1[20], str2[20],remp = '';
int size1,i,j,temp;
printf ("Input the first string");

[Code]...

View 6 Replies View Related

C++ :: How To Do Substring To Get Last 4 Characters

May 8, 2013

let says i have char *yytext = "p103_stb" 0r "p0_stb" or "p100_stb"

How to do substr to get the "_stb" in C?

View 12 Replies View Related

C++ :: Find Longest Name / Display It And Tell How Many Letters It Have

Feb 27, 2014

I am trying to make a program into which you writre for example ten Names or words or etc. and it would find the longest name/word write it and the numbers of characters too but I have problem with displaying that name. Here is me source code, the problem is here "vitaz=szInput;" i don't know how to save that longest name/word.

#include <cstdlib>
#include <iostream>
#include <string.h>
using namespace std;
int main () {
char a;
char szInput[256],vitaz[256];

[Code] .....

View 5 Replies View Related

C :: How To Find Longest Series Of Even And Positive Numbers

Mar 6, 2015

Example input: 2 4 6 -1 7 3 -2 1

Output: 3 3 (longest series of even is 3, longest series of positive is 3)

Here is the code:

Code:

#include <stdio.h>
int even(int x) {
return x % 2 == 0;
}
int positive(int x) {
return x>0;

[Code]...

My question is how to write this code if the prototype of function is:

Code: void series(int *array, int n, int (*s)(int), int **begining, int *lenght);

View 1 Replies View Related

C/C++ :: Find Longest Series Of Even And Positive Numbers?

Mar 16, 2015

program:

Example input: 2 4 6 -1 7 3 -2 1
Output: 3 3 (longest series of even is 3, longest series of positive is 3)

Here is the code:

#include <stdio.h>
int even(int x) {
return x % 2 == 0;
}

[Code].....

My question is how to write this code if the prototype of function is:

void series(int *array, int n, int (*s)(int), int **beginning, int *length);

View 1 Replies View Related

C++ :: Program That Uses Recursion To Find Longest Increasing Sequence From A Grid In File

Mar 25, 2013

Any examples of a c++ program that uses recursion to find the longest increasing sequence from a grid in a file. Like

2 4 6 8
10 12 14 16
18 20 22 24

I have to use a structure named Point and a structure named Sequence.

const int MAXROWS = 4;
const int MAXCOLS = 4;
const int MAXFILENAME = 255;
// Structure used to define a point (x,y) in the grid.
typedef struct {
int x, y;

[Code] .....

View 1 Replies View Related

C/C++ :: Finding And Printing A Substring In A String?

Feb 21, 2015

i couldnt solve the algorithm exactly. The program asks the user for a string. "Bugun h@v@ cok g'uzel" for example. then the program asks for another string. If that string doesnt exists in the main string program should say there isnt any substring. If it exist then the program should print the remaining part of main string. For example:

Write the first string: Tod@y weather is be'@utiful
write the substring : ug
>>ugun h@v@ cok guzel
write the substring :wldnqwbdbj
>>there isnt any substring
Here where i came so far

#include <stdio.h>
int main()
{
char mainstr[50],substr[50];

[Code]....

View 7 Replies View Related

C/C++ :: How To Compare A String To A Vector Substring

May 9, 2014

I would like to compare two strings, one of which is an independently stored string - the other being a string within a vector. However, i do not know how to do this, as

string thisString = "yes";
vector<string> stringHere;
stringHere.push_back("no");
if (thisString == stringHere[0]) {
cout << "It worked." << endll;
}

does not appear to work.

View 2 Replies View Related

C++ :: Longest String Does'n Print On Same Line

Aug 4, 2014

I try to learn string class, resolving some problem, but i have some dificulties.The is ok, but when i print the longest string it does'n print on the same line.I enter the number of string, after that i enter the first string until i introduced from keyboard "#" character. I enter the second string and so on.Look at these example :

For i = 3;

Text[0] : I learn class String#
Text[1] : I dont learn class String#
Text[2] : String#

It print me like that : Text[1] :

I dont learn class String More than that look at the next example :

For i = 3;

Text[0] : I learn class String#abcdef
Text[1] : I dont learn class String#
Text[2] : String#

You see that in the first sentence i have continue to introduce some characters after # character and look what is happened :

Text[1] : abcdef
I dont learn class String

#include<iostream>
#include<string>
using namespace std;
int main() {
string text[100], cuvant;
int i, j, m, lung = 0;
cout << "

[code]....

View 3 Replies View Related

C++ :: Find All Unique Triplet In Given Array With Sum Zero

Feb 26, 2015

I got all unique triplet from below code but I want to reduce its time complexity. It consist three for loop. So my question is, Is it possible to do in minimum loop that it decrease its time complexity. code will be execute in minimum time.

#include <cstdlib>
#include<iostream>
using namespace std;
void Triplet(int[], int, int);
void Triplet(int array[], int n, int sum) {

[Code] .....

View 7 Replies View Related

C :: How To Print Characters But No String Just Array Of Characters

Mar 20, 2014

so my question is i want to print characters,no string just an array of characters,i do this but it s not working,maybe i have to put the '' at the end?

Code:

int main() {
int i;
char ch[5];
for(i = 0; i < 5; i++) {
scanf("%c",&ch[i]);

[Code]...

View 6 Replies View Related

C/C++ :: Comparing Two String Arrays For Unique Words?

Oct 2, 2014

I'm looking to take in an array of less than 50 strings, and I want to find all of the unique words in that array (omitting the words that are repeated) and then outputting the unique words and unique word count. My code compiles, but my unique array is couting all of the words contained in the original array regardless of uniqueness.

#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
using namespace std;
int main() {
cout << "Please type in some words." << endl;
cout << "Type END and return when you are finished." << endl;

[code].....

This is what I get back.

You typed the following 14 words: red, green, blue, red, red, blue, green, blue, orange, red, reg, apple, banana, banana, END,

You typed the following 0 unique words: red, green, blue, red, red, blue, green, blue, orange, red, reg, apple, banana, banana, END

I'm not worried about the unique count yet, I just want to get the unique array containing the correct strings.

View 3 Replies View Related

C/C++ :: Write Program That Determines If String Has All Unique Lowercase

Sep 16, 2014

I am trying to write a program that determines if a string has all unique lowercase letters. However i am unable to understand how to write the code as i am very new to C++ and my professor has given us some tasks to do and has not taught us any C++. i am familiar with the syntax but am not able to understand the tasks properly and able to complete them successfully

#include <iostream>
#include <cctype>
using namespace std;

[Code].....

View 6 Replies View Related

C++ :: Forming Unique String With Single Occurrence Of Words

May 10, 2012

I am trying to form unique string from other string which is having multiple presence of same word as,

string testA = "one
two
three
four
one
seven wo";

now new string should contain single occurrence of words "one" and "two" so that new string will look like,

string testB = "one
two
three
four
seven"

View 3 Replies View Related

C/C++ :: Find Number Of Characters In TXT File Without Spaces

Feb 17, 2015

How does one read the number of characters in a .txt file excluding the spaces? Here is my code so far. I am getting 67, which is the correct number including spaces but can't find out how to exclude them. Here's my code!

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
/////////------------------/////////
//Function Prototypes//
int fileLength();

[Code] .....

View 6 Replies View Related

C :: Comparing Of Characters In Given String From Input String?

Feb 7, 2013

I am stuck in this program, Be given a string of chars, where each single char belongs to the following alphabet: a..zA..Z0..9 (So, in the string there are only lowercases, uppercases and digits. No blank, no comma, ...). For every char of the given alphabet, count how many times in the string

1-- the char belong to a sequence of identical chars whose length is at least three (i.e.: in the string cc74uyrpfccc348fhsjcccc3848djccccc484jd for three times the character 'c' satisfies this condition)

Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>

[Code]...

2-what is the longest substring of characters strictly rising interm of ASCII code(the following is greater (>) of the previous)

3- what is the longest substring of successive characters interm of given string rannge (i.e.: fhkjshdfruytyzABCDEfglsj => 7)

View 1 Replies View Related

C++ :: Reading Characters From String

Apr 13, 2013

i have a string which is n characters long. i need to read say 20 characters at a time, wait for the user to type OK and then send another 20 characters. wait for the user to type OK and send 20 characters again until we get to the nth character.

View 3 Replies View Related

C++ :: Removing Characters From A String

Nov 1, 2013

I want to remove a particular character from a string. Say '.'. I've tried the following:

void removeDots(std::string &x)
{
std::remove_if(x.begin(),x.end(),[](char c){return (c == '.');});
}

This has the effect of removing the dots but keeping the length of the string the same, so old characters are left over at the end. Is there an extra action to do to x to make it the right size or is there a better way of doing it?

View 3 Replies View Related

C++ :: Reversing N Characters In A String?

Dec 26, 2013

I have a string like str="ABCDEFGHIJK";

need o/p like this str="CBAFEDIHGJK"

am getting "CBA" correctly after that its not printing anything.

int main()
{
string str="ABCDEFGHIJK";
char str1[10],rev[10];
int n=str.length(),count=0,c=3,k=0,j=0;

[Code].....

View 10 Replies View Related

C/C++ :: How To Uppercase All Characters Of A String

Oct 28, 2014

I'm working on a programming challenge and i need to uppercase all characters of the string.

string upperCaseIt(string& name){
for(int index = 0; index < name.length(); index++){
name[index] = toupper(name[index]);
return name;
}
}

My problem is that it only uppercase the first character of the string.

View 2 Replies View Related

C/C++ :: How To Cout The String Characters Themselves

May 11, 2014

Iam working with arrays and i cant get to the write solution to cout the characters.

the Question is : Write a program that inputs a character string from the user as an input (using cin.get())and store it in myStr[ ] array.Assume that the length of the input string is less than 100 characters and the string may contain lower case, upper case, and/or symbols.The program should then print the number of lower case, upper case, digits, and symbols along with the characters themselves.

my code :

#include <iostream>
#include <string>
#include<iomanip>
using namespace std;
int main() {
int ctr1=0, ctr2=0, i=0, ctr3=0;

[Code] ...

What i have now, how can i cout the uppercase characters and the lower case characters and the symbol characters !

View 3 Replies View Related

C/C++ :: How To Ignore Certain Characters In A String

Sep 18, 2014

I am trying to cout just the first 5 characters the user enters into a string. I'm not sure how I can discard or not show the rest of the characters they try to enter after 5.

#include <iostream>
#include <string>
using namespace std;
int main() {
string random;
cout << "Enter any word." << endl;
cin >> random;
cout << random; //want to ignore everything after first 5 characters entered.
return 0;
}

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved