srikantaggarwal
BAN USERWhy future check mates are being checked.. The question asks if any checkmate at current position ?
We can consider possible movements for KINg and see if any of the opposition pieces can kill it ?
Not able to get the (3) point can u explain further? How does it brings the wrong pointer value to right place?
- srikantaggarwal September 17, 2012Hi Naseer Quick sort is inplace or not?
- srikantaggarwal September 06, 2012Code :
#include <stdio.h>
#define MAX_LENGTH 100
int is_special(char ch)
{
if(ch == ',' || ch == '{' || ch == '}')
return 1;
return 0;
}
main()
{
char S[MAX_LENGTH];
int i, alph = 0;
scanf("%s", S);
for(i = 0; S[i] != '\0'; i++)
{
if(is_special(S[i]))
{
if(alph)
printf("\n");
if(S[i] != ',')
printf("%c\n", S[i]);
alph = 0;
}
else
{
printf("%c", S[i]);
alph = 1;
}
}
return 0;
}
Please give me your suggestions.
- srikantaggarwal August 28, 2012How is this code :
#include <stdio.h>
main()
{
char S[] = "00x0000ac00ac00a00";
int i, j = -1, count = 0;
for(i = 0; S[i] != '\0'; i++)
{
if(S[i] == '0')
{
count++;
if(count >= 3)
{
if(count == 3)
{
S[++j] = '0';
S[++j] = '0';
}
S[++j] = '0';
}
}
else
{
if(count == 1)
S[++j] = '0';
S[++j] = S[i];
count = 0;
}
}
S[++j] = '\0';
printf("%s\n", S);
return 0;
}
Please let me know if you find it difficult to understand before reducing -ve voting.
- srikantaggarwal August 28, 2012F**k all.... B******s.
- srikantaggarwal August 24, 2012Why no vote for my code.. I think its the best solution possible.. Please let me know if ne issue?
- srikantaggarwal August 21, 2012Well vote up thn.. :P
- srikantaggarwal August 21, 2012swapping to keep the elements below zero in first half.. and elements greater than zero in third half.. the elements equal to zero comes in between. :)
- srikantaggarwal August 21, 2012It seems due to indentation people are getting confused.. As I take the array from user.. I am using 2 for loops but they are not nested. :)
I only parse the array once... indicated by second for loop.
Man its O(n)
- srikantaggarwal August 21, 2012Why voted -ve?
- srikantaggarwal August 21, 2012In single parse:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int *arr, n, i, j, k;
scanf("%d", &n);
arr = (int *)malloc(sizeof(int)*n);
for(i = 0; i < n; i++)
scanf("%d", &arr[i]);
i = -1;
k = n;
for(j = 0; j < k; j++)
{
if(arr[j] > 0)
{
int temp;
k--;
temp = arr[j];
arr[j] = arr[k];
arr[k] = temp;
j--;
}
else if(arr[j] < 0)
{
int temp;
i++;
temp = arr[j];
arr[j] = arr[i];
arr[i] = temp;
}
}
printf("\n");
for(i = 0; i < n; i++)
printf(" %d ", arr[i]);
return 0;
}
void mirror_image(node *root)
{
if(root != NULL)
{
node* temp;
mirror_image(root->left);
mirror_image(root->right);
temp = root->left;
root->left = root->right;
root->right = temp;
}
}
Code :
int delete_kth_node( node *head, int n, int k)
{
node *current_node = head;
while(n > 1)
{
int dist = (k % n)-1;
node *temp = NULL;
if(dist == -1)
dist = n-1;
while(dist > 0)
{
current_node = current_node->next;
dist--;
}
temp = current_node->next;
current_node->next = temp->next;
if(temp == head)
head = temp->next;
free(temp);
temp = NULL;
n--;
printf("\n");
print_list(head, n);
current_node = current_node->next;
}
return head->val;
}
RepMelodyTHeckler, abc at ABC TECH SUPPORT
Earned praised for my work lecturing about get love back by vashikaran. Spent childhood promoting art posters in Jacksonville, FL ...
x2 is the distance b/w D1 , D2 or start, D2 ?
- srikantaggarwal September 17, 2012