rohit
BAN USERi am a student of bit mesra .
i am very interactive, my programming is very well.
i want to enhance my skills.
- 0of 0 votes
AnswersBy tossing a coin we can get either head or tail, i have a function toss() which return head or tail with equal probability.
- rohit in India
You have to write a function for dice which will return number from 1-6 with equal probability.
constraints : you can not use random function, you can use only toss function.| Report Duplicate | Flag | PURGE
Practo Software Engineer / Developer Algorithm - 2of 2 votes
AnswersYou are given an array of size N containing negative and positive real numbers. Zero may or may not be present in the array. The requirement is to rearrange the array using O(N) time and O(1) space so that all negative numbers come before all positive elements. Develop a program to read a real number array of size N from user, and then arrange it as explained above.
- rohit in India
Constraints :
(i) The value of N has to be read from user, and the memory for array has to be allocated dynamically. The real numbers will be also read from user. The menu-driven program should also have an option to populate the array with random data, if the user wants to do so.
(ii) A maximum of 3 passes allowed over the entire array. O(N) time expected.
(iii) O(1) extra space permitted – creating copy of array etc not allowed.
(iv) Program must work properly even if zero is NOT present in array.| Report Duplicate | Flag | PURGE
IBM Software Engineer in Test
- 0 Answers Compiler Design
0
- rohit January 28, 2014
down vote
favorite
Creating email addresses form names
You have given a file containing names of several persons. The file will have exactly one name is each line. You need to create email address ending with @bitmesra.ac.in from those names. the rule for creating email address is defined below: A name will be expressed in the following form: ............
Let F(s) denote the first character of string s. so, email id will be F(string 1)F(string 2)........._lastString@bitmesra.ac.in Some names and their corresponding email id's are listed below as an example
Sachin Ramesh Tendulkar s_r_tendulkar@bitmesra.ac.in Rahul S Dravid r_s_dravid@bitmesra.ac.in
You need to generate a grammer for this.
note: there may multiple spaces b/w names.
my code is here...
#include<cstdio>
#include<cstring>
#include<cctype>
int main()
{
char str1[100],str2[100];
char str3[] = "@bitmesra.ac.in";
while(gets(str1))
{
int index,k=0;
str2[k] = tolower(str1[0]);
for(int i=1;i<strlen(str1);i++)
{
if(str1[i]==' ')
{
index = i;
if(isalpha(str1[i+1]))
{
k++;
str2[k] = '_';
k++;
str2[k] = tolower(str1[i+1]);
}
}
}
index= index + 2;
for(int i=index;str1[i]!='\0';i++)
{
k++;
str2[k] = tolower(str1[i]);
}
str2[++k] = '\0';
strcat(str2,str3);
printf("%s\n",str2);
}
return 0;
}
how to desing CFG for this...| Flag | PURGE - 2 Answers data structure program
Checking if a graph is a valid tree : A graph is a tree if and only if it is connected and does not contain any cycles, no self-loops and no repeated edges. Develop a program which reads a graph from user, and determines if it is a tree or not.
- rohit March 22, 2013
Constraints :
(i) The graph will be read from a text file. Each line in the text file will contain an (x, y) pair which represents that there is an edge from vertex x to vertex y. (ii) If graph has V vertices, and E edges, then expected space complexity is O(V + E) and expected time complexity is O(V + E).| Flag | PURGE