prashanthreddy.mtech
BAN USER#include <stdio.h>
#include <string.h>
void trim(char *p);
main()
{
char msg[] = "hi this is test message";
trim(msg);
printf("%s",msg);
}
void trim(char *p)
{
char *m,*n;
m = n = p;
int space = 1;
while(*p != '\0')
{
if(isspace(*p) && (space == 1))
{
*m = *p;
space = 0;
m++;
}
if(isalnum(*p))
{
*m = *p;
m++;
space = 1;
}
p++;
}
*m = '\0';
p = n;
}
#include <stdio.h>
int main()
{
int str;
int m = 0, n = 0;
int i,j;
printf("enter integer, i value, j value \n");
scanf("%d%d%d",&str,&i,&j);
if(str & (1 << i))
m = 1;
if(str & (1 << j))
n = 1;
if(m)
{
str |= (1 << j);
}
else
{
str &= (~(1<<j));
}
if(n)
{
str |= (1 << i);
}
else
{
str &= (~(1<<i));
}
printf("str = %d\n", str);
return 0;
}
Dynamic allocation is not possible fr char pointer, for that u need to use this procedure:
char arry[100] ; /* store data into this */
char *p = malloc(sizeof(strlen(arry)*char));
strcpy(p,arry);
Treeset
- prashanthreddy.mtech February 26, 2014Try Tree sort, its just 2 steps code.
- prashanthreddy.mtech June 17, 2013We can store initially one complete into map as line as the key, now start with second file, try to insert into map, if it fails, print the repeated line and remove it from the map. Even if that line inserted into map, delete that entry since we can reduce the map size. So finally Map will have non duplicate entries from both the file. Because there is a chances that Line1 in file1 matches with Last line in file2. If this is the case, we want to store atleast 1 map. If there is any issue in retrieving the string, due to hashing....we can use double hashing.
- prashanthreddy.mtech June 17, 2013here we are taking each student separately and adding score to him/her. if there are more subjects for some students, then we can add score to them separately. because we are not maintaining an array to store their score.
- prashanthreddy.mtech June 17, 2013Have you ran and checked it, because u kept low and high as fixed. you are only incrementing/decrementing mid. Correct me, if i am wrong.
- prashanthreddy.mtech June 17, 2013I think, why don't we use TreeSort, which sorts automatically, when the input data comes in and its also a Dynamic Array.
- prashanthreddy.mtech June 17, 2013Instead of Map, we can use enum.
- prashanthreddy.mtech June 17, 2013According to my understanding, we can use Map
Map<String, Integer> studentScores = new HashMap<String, Integer>();
-> For 1st test, we will add, student id and his first test score
-> For second test, we will get the student id and add the second test score to first test.So, it will be O(1).
-> we wll repeat this for 2nd,3rd,4th test and for 5th test we will add score and also we will calculate average and score in students id.
I hope, we can use B Trees. Each node will have more than 2 children. All node will represent keys. Depending on the key , it will fetch the movie.
- prashanthreddy.mtech June 15, 2013Yeah, i hope so. It depends on how well u implement hashing Algorithm.
- prashanthreddy.mtech June 12, 2013Hi,
You can use Hash Set and Hash Map for this.
-> Initially when you are reading the data insert into hash set, if and integer is repeating insert into hash map as a key, and add count. If that integer repeats again, then increment count. (As hash set doesn't allow duplicates) .
-> Hope this should work fine. as hash set insert into O(1) time and HashMap also takes O(1) time.
Create a Map with userid as key and time stamp that he logged in.
-> when ever user log-in's into the system, store his userid and time stamp into the map and store this into a Queue.
-> When ever time stamp crosses 1 min insert an empty data.
-> So, when the queue reaches 2o min, flush out the first 10 minutes data. As the Queue will hav latest 10 min data.
-> hope this should work.
In Dictionary is there any word, starting with special characters means #, ?.. etc. If it starts like that also, it will store the first alphabet, as i am checking with letters which we got previously. here checking 'm' with 'g'.
- prashanthreddy.mtech June 10, 2013Hi,
I dont know whether i am clear with the question. My Answer is,
you just want to find out the order of Alphabets.
-> Take the first string and in that take out the first Alphabet, this represents the first alphabet.
-> Select second string, such that 1st alphabet should be different, than the previous, which represents second alphabet in the series.
EX:
Let dictionary be
Gun
God
Graveyard
Money
Maintain
-> here 1st alphabet is g, in the second string check whether 1st alphabet == g, if yes, skip else store, which represents Second alphabet.
-> Hope this solution can work. Now once u get all the alphabets u can store in a graph or linked list.
My Solution can be, lets take the number series
2 1 2 1 2 3 4
And if we want to find out the position of 3,
1) Start with 2, since 3-2 =1, move 1 position and
2) Find the difference, 3-1 = 2, so move 2 positions.
3) next 3-1 = 2, again move 2 positions
4) Now 3-3 = 0, so we got the solution and its not a linear search.
Hope this should work for all the series
So, how can you do for this series 2 1 2 1 2 3 4, if we want to find out the position of 3.
- prashanthreddy.mtech June 06, 2013BST is applicable in Serialization. You can take the complete File structure, serialize in a inorder fashion and can send over the network
- prashanthreddy.mtech May 24, 2013What you can do, if some one has written the code. U can put print statements at regular intervals, hope this should help. But initially it takes some more time, but easy to find out the bugs.
- prashanthreddy.mtech May 23, 2013He already mentioned, that we should not traverse the complete Array. Then how can you find the sum of complete Array
- prashanthreddy.mtech May 22, 2013Why don't we try inorder traversal as it clearly mentioned its a BST. So, it will print elements in ascending order. So, the 2nd element from the right most is the answer.
- prashanthreddy.mtech March 28, 2013If you have code with wait and notify, can you please post it. When i tried , the 1st thread itself is going into infinite wait.
- prashanthreddy.mtech March 27, 2013Is there any 2d Array, which accepts character and Integer, other than collections. Correct me if i am wrong.
- prashanthreddy.mtech March 27, 2013I tried its not wrking, So finally i modified like this, then it started working.
- prashanthreddy.mtech March 27, 2013Hi, The question itself stating that we have to use Threads.
- prashanthreddy.mtech March 27, 2013Hav you executed the code?, i think it will not wrk.If you dont call print2() from print1() and print3() from print2()..... It will not work sequentially.
- prashanthreddy.mtech March 27, 2013import java.util.*;
public class CharacerReputution {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int counter =1, arycounter=0;
String s1 ="aabcdaefbbbbbb";
Map<Character,Integer> m1 = new HashMap<Character,Integer>();
char chArry[] = new char[6];
for(int i=0;i<s1.length();i++)
{
if(m1.containsKey(s1.charAt(i)))
{
counter = m1.get(s1.charAt(i));
counter += 1;
m1.remove(s1.charAt(i));
m1.put(s1.charAt(i), counter);
}
else
{
counter =1;
m1.put(s1.charAt(i), counter);
chArry[arycounter] = s1.charAt(i);
arycounter += 1;
}
}
int max=0,bet=0;
char c;
max = m1.get(chArry[0]);
c = chArry[0];
for(int i=1; i< chArry.length-1; i++)
{
if(m1.containsKey(chArry[i]))
{
bet = m1.get(chArry[i]);
if( max < bet)
{ max = bet;
c = chArry[i];
}
}
}
System.out.println(" max charac =" + c + " rep= "+ max);
}
}
package threads;
public class TwoThreadsSync
{
static int counter1 =0, counter2 =0,counter3 =0;
static int arry[] = {1,2,3,4,5};
static char chArry[] = {'a','b','c','d','e'};
static String strArry[] = {"one","two","three","four","five"};
private static int turn =1;
private static class First extends Thread
{
public void run()
{
while(counter1 <=4)
{
if(turn == 1)
{
System.out.println("First Thread: "+arry[counter1]);
counter1 += 1;
turn=2;
}
}
}
}
private static class Second extends Thread
{
public void run()
{
while(counter2 <=4)
{
if(turn == 2)
{
System.out.println("Second Thread: "+chArry[counter2]);
counter2 += 1;
turn=3;
}
}
}
}
private static class Third extends Thread
{
public void run()
{
while(counter3 <=4)
{
if(turn == 3)
{
System.out.println("Third Thread: "+strArry[counter3]);
counter3 += 1;
turn=1;
}
}
}
}
public static void main(String []args)
{
First f1 = new First();
Second s1 = new Second();
Third t1 = new Third();
f1.start();
s1.start();
t1.start();
}
}
RepColaraJoshi, Floor manager at Thomes
By profession, I am Floor manager in the Thomes store. I am passionate about astrology and read tronto cards, horoscopes ...
For comparing strings
- prashanthreddy.mtech July 02, 2014-> One way is to convert into ASCII, (int)(s.charAt(i)) will give ascii value.
-> Use Tree Set and interchange words