Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

print a semicolon using Cprogram without using a semicolon
any where in the C code in ur program!!

Answer Posted / sorabh

#include<stdio.h>
#include<list>
#include<vector>

using namespace std;
char str[100002];
int dist[100002];
int n;

void BFS(int s)
{
vector<bool> visited(10,false);
list<int> queue;
dist[s] = 0;
queue.push_back(s);

while(!queue.empty())
{
s = queue.front();
queue.pop_front();

vector<int> temp; temp.clear();
if(s==0) temp.push_back(1);
else if(s==n-1) temp.push_back(n-2);
else { temp.push_back(s-1); temp.push_back(s+1);}
int sz=temp.size();
for(int i=0; i<sz; i++)
{
int node=temp[i];
if(1+dist[s]<dist[node]) {
dist[node] = 1+dist[s];
if(node==0) return;
queue.push_back(node);
}
}
if(!visited[str[s]-48]) {
sz=pos[str[s]-48].size();
for(int i=0; i<sz; i++)
{
int node=pos[str[s]-48][i];
if(1+dist[s]<dist[node]) {
dist[node] = 1+dist[s];
if(node==0) return;
queue.push_back(node);
}
}
visited[str[s]-48]=true;
}
}
}

int main()
{
scanf("%s",str);
n=strlen(str);
for(int i=0; i<n; i++) {
pos[str[i]-48].push_back(i);
dist[i] = INT_MAX;
}
BFS(n-1);
printf("%d",dist[0]);
return 0;
}

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Cluster head selection in Wireless Sensor Network using C programming language.

3809


how to create a 3x3 two dimensional array that will give you the sums on the left and bottom columns

3702


can you use proc sql to manpulate a data set or would u prefer to use proc report ? if so why ? make up an example and explain in detail

3105


Write a Program in 'C' To Insert a Unique Number Only. (Hint: Just Like a Primary Key Numbers In Database.) Please Some One Suggest Me a Better Solution for This question ??

2540


How can I Create a C program in splitting set of characters to specific subsets. Example: INPUT SET OF CHARACTERS: Therefore, my dear brothers and sisters, stand firm. Let nothing move you. Always give yourselves fully to the work of the Lord, because you know that your labor in the Lord is not in vain. SPLIT INTO HOW MANY CHARACTERS PER SUBSETS: 10 OUTPUT: Therefore, my dear b rothers an d sisters, stand fir m. Let not hing move you. Alway s give you rselves fu lly to the work of t he Lord, b ecause you know that your labo r in the L ord is not in vain.

2601


What is data _null_? ,Explain with code when u need to use it in data step programming ?

3404


How can you relate the function with the structure? Explain with an appropriate example.

3516


What is full form of PEPSI

2484


How to palindrom string in c language?

11345


how to programme using switch statements and fuctions, a programme that will output two even numbers, two odd numbers and two prime numbers of the users chioce.

2732


Set up procedure for generating a wire frame display of a polyhedron with the hidden edges of the object drawn with dashed lines

3627


write a program for area of circumference of shapes

2630


Given a spherical surface, write bump-mapping procedure to generate the bumpy surface of an orange

3429


Develop a routine to reflect an object about an arbitrarily selected plane

3694


Can you send Code for Run Length Encoding Of BMP Image in C Language in linux(i.e Compression and Decompression) ?

4461