C,C++/JAVA/BASH/ASM ARENA

वह प्रदीप जो दीख रहा है झिलमिल दूर नही है थक कर बैठ गये क्या भाई मन्जिल दूर नही है चिन्गारी बन गयी लहू की बून्द गिरी जो पग से चमक रहे पीछे मुड देखो चरण-चिनह जगमग से बाकी होश तभी तक, जब तक जलता तूर नही है थक कर बैठ गये क्या भाई मन्जिल दूर नही है अपनी हड्डी की मशाल से हृदय चीरते तम का, सारी रात चले तुम दुख झेलते कुलिश का। एक खेय है शेष, किसी विध पार उसे कर जाओ; वह देखो, उस पार चमकता है मन्दिर प्रियतम का। आकर इतना पास फिरे, वह सच्चा शूर नहीं है; थककर बैठ गये क्या भाई! मंज़िल दूर नहीं है। दिशा दीप्त हो उठी प्राप्त कर पुण्य-प्रकाश तुम्हारा, लिखा जा चुका अनल-अक्षरों में इतिहास तुम्हारा। जिस मिट्टी ने लहू पिया, वह फूल खिलाएगी ही, अम्बर पर घन बन छाएगा ही उच्छ्वास तुम्हारा। और अधिक ले जाँच, देवता इतन क्रूर नहीं है। थककर बैठ गये क्या भाई! मंज़िल दूर नहीं है।

Interview question – Linked list June 1, 2011

Filed under: Uncategorized — whoami @ 08:44


/*
Given a linked list of the form, 1->2->3->4->5->6, convert it into the form 2->1->4->3->6->5. Note that the nodes need to be altered and not the data contained in them; 

*/

#include<stdio.h>
#include<malloc.h>


struct node{
 int a;
 struct node *next;
}*start=NULL;



void add(int item)
{
  struct node *tmp=(struct node *)malloc(sizeof(struct node));
  struct node *tmp2;
  tmp->a=item;
  tmp->next=NULL;

  tmp2=start;
  if(tmp2!=NULL)
  {
  while(tmp2->next!=NULL) tmp2=tmp2->next;
  
    tmp2->next=tmp;
  }
  else
   start=tmp;
  

}

void display()
{
  struct node *tmp=start;
  while(tmp!=NULL){
    printf("%d ",tmp->a);
    tmp=tmp->next;
  }
}

void reverse()
{
  struct node *tmp=start;
  struct node *tmp2=start->next;
  struct node *tmp3=tmp2;
  if(start->next==NULL) return;
  tmp->next=NULL;
  while(tmp2!=NULL)
  {
    tmp3=tmp2->next;
    tmp2->next=tmp;
    tmp=tmp2;
    tmp2=tmp3;
  }
   start=tmp;
   
}



void swap()
{
   struct node *tmp=start;
   struct node *tmp2=tmp->next,*tmp3,*save;
   if(tmp2==NULL) return;
   
   if(tmp2->next==NULL) 
   {
      tmp3=tmp;
      tmp->next=tmp2->next;
      tmp2->next=tmp;
      start=tmp2;
      return ;
   }

   if(tmp2->next->next==NULL)
   {
      tmp3=tmp2->next;
      tmp->next=tmp3;
      tmp2->next=tmp;
      start=tmp2;
      return ;
    }       
   
   
   tmp3=tmp2->next;
   tmp2->next=tmp;
   tmp->next=tmp3->next;
   start=tmp2;
   tmp=tmp3;
   tmp2=tmp->next;
   while(1)
   {
     if(tmp2==NULL||tmp2->next==NULL||tmp2->next->next==NULL) break;     
     tmp3=tmp2->next;
     if(tmp==NULL||tmp3->next==NULL) break;
     tmp2->next=tmp;
     tmp->next=tmp3->next;
   
     
     tmp=tmp3;
     
     tmp2=tmp->next;
     
    
          
   }
   
   if(tmp!=NULL&&tmp2!=NULL)
   {
     if(tmp2->next==NULL)
     {
      tmp2->next=tmp;
      tmp->next=NULL;
      
     }
     else if(tmp2!=NULL)
     {
       
       save=tmp2->next;
       tmp2->next=tmp;
       tmp->next=save;
       
     }
   }
   
}   
     
     
   
   


int main()
{
  int item;
  printf("enter the item one by one\nenter -1 to stop\n");
  while(1)
  {
     
     item;
     
     scanf("%d",&item);
     if(item==-1) break;
     add(item);
  }
  printf("\nThe single linked list is\n");
  display();
  reverse();
  printf("\nThe reversed linked list is\n");
  display();
  printf("\nThe single linked list is\n");
  reverse();
  display();
  printf("\nThe swapped(only 2 adjacent elements) linked list is\n");
  printf("\nGiven a linked list of the form, 1->2->3->4->5->6, convert it into the form 2->1->4->3->6->5. Note that the nodes need to be altered and not the data contained in them.\n\n"); 
  swap();
  display();

return 0;
}


 

Level Order Traversal(BFT) of a Binary Tree May 25, 2011

Filed under: Uncategorized — whoami @ 18:53

//level order traversal of a tree.
//here tree that is created is BST although it will work for every binary tree
#include<stdio.h>
#include<malloc.h>
#include<queue>
using namespace std;

struct node{
  int item;
  struct node *left;
  struct node *right;
};

struct node *root=(struct node *)malloc(sizeof(struct node));


void insert(int data)
{
  struct node *tmp=(struct node *)malloc(sizeof(struct node));
  struct node *tmp2;
  struct node *save=(struct node *)malloc(sizeof(struct node));

  tmp->item=data;
  tmp->right=NULL;
  tmp->left=NULL;

  tmp2=root;
  while(1)
  {
    if(tmp2==NULL) break; 
    if(data>tmp2->item)
    {
       save=tmp2;
       tmp2=tmp2->right;
    }
    else if(data<tmp2->item)
    {
       save=tmp2;
       tmp2=tmp2->left;
    }
  }
  if(save->item<data)
  {

     save->right=tmp;
  }
  else if(save->item>data)
  {
     save->left=tmp;
  }

}     

//////////////////level order traversal begins//////////////////////
void bfs()
{
  queue<struct node *>q1;
  queue<struct node *>q2;
  struct node *tmp;
  struct node *tmp2;
  q1.push(root);//root
  while(1)
  {
     
     while(!q1.empty())
     {
         tmp2=q1.front();
         if(tmp2->left!=NULL)
         {
           q2.push(tmp2->left); 
         }
         if(tmp2->right!=NULL)
         {
            q2.push(tmp2->right);
         }
         printf("%d ",tmp2->item); 
         q1.pop(); 
      }
      if(q2.empty()) break;
      printf("\n");
      
      while(!q2.empty())
      {
        q1.push(q2.front());
        q2.pop();
      }
   } 

}

//////////////////level order traversal end//////////////////////



int main()
{
  int data;
  
  //create binary search tree
  printf("enter the root element");
  scanf("%d",&data);
  root->item=data;
  root->left=NULL;
  root->right=NULL;
 
  while(1)
  {
    printf("enter -1 to stop");
    scanf("%d",&data);
    if(data==-1) break;
    insert(data);
  }

  bfs();//level order traversal

return 0;
}

 

2010 in review January 2, 2011

Filed under: Uncategorized — whoami @ 08:51

The stats helper monkeys at WordPress.com mulled over how this blog did in 2010, and here’s a high level summary of its overall blog health:

Healthy blog!

The Blog-Health-o-Meter™ reads Fresher than ever.

Crunchy numbers

Featured image

A helper monkey made this abstract painting, inspired by your stats.

A Boeing 747-400 passenger jet can hold 416 passengers. This blog was viewed about 8,900 times in 2010. That’s about 21 full 747s.

 

In 2010, there were 95 new posts, growing the total archive of this blog to 299 posts. There were 4 pictures uploaded, taking up a total of 157kb.

The busiest day of the year was May 4th with 134 views. The most popular post that day was SPOJ UBoat Problem code: HS09UBT.

Where did they come from?

The top referring sites in 2010 were en.wordpress.com, google.co.in, tausiq.wordpress.com, alliraph.wordpress.com, and google.com.

Some visitors came searching, mostly for c++ bash arena, “s1 = (char*)((int)s1 + (int)s2)”, how to unlock yum, anarc,spoj, and unlock yum.

Attractions in 2010

These are the posts and pages that got the most views in 2010.

1

SPOJ UBoat Problem code: HS09UBT February 2010

2

SPOJ 5842. Polybius square February 2010
1 comment

3

nfa to dfa conversion best explained July 2010

4

Compile Linux kernel fedora 11 January 2010

5

How to unlock yum in fedora February 2010
2 comments and 1 Like on WordPress.com,

 

Exception in thread “main” java.lang.NoClassDefFoundError: Main September 4, 2010

Filed under: Uncategorized — whoami @ 18:14
Tags: ,

Sometimes , inspite of setting proper classpath for JAVA_HOME, getting this Error on running

$java filename(without exten)  – Producing error means something strange. I too got irritated and finally found that its bcz its not considering the present working directory.

So by doing this

$java -classpath  .  filename

problem was solved

Here is the Great Hepful Link

 

Modular Exponentiation September 4, 2010

Filed under: C,C++ Programs — whoami @ 18:05
Tags: ,

Problem5

CodeChef

ACCEPTED


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
using namespace std;
int  main()
{
 int A,B;
 while(1)
 {
 scanf("%d%d",&A,&B);
 if(A==0&&B==0) break;

 int base,power,modulus;
 modulus=1000000;
 base=A;power=B;
 long long result = 1;
 for (int i = 31; i >= 0; i--) {
 result = (result*result) % modulus;
 if ((power & (1 << i)) != 0) {
 result = (result*base) % modulus;
 }
 }

 int ans=(int) result;

 printf("%d\n",ans);
 }


return 0;
}

 

nfa to dfa conversion best explained July 26, 2010

Filed under: C,C++ Programs,Compiler — whoami @ 16:29
Tags: ,

Here is the example from ullman sethi

link

other links of programs

 

Programming Quest June 29, 2010

Filed under: C,C++ Programs — whoami @ 09:02
Tags: , , ,

From YoungProgrammer.com

LCM-GCD based question

Question:

We all interested in mathematics and world are divided in to two parts.
One who are interested in mathematics and other who are afraid of mathematics.
Here is a equation:
( X * N ) % Y = 0

Given two number X & Y you have to find minimum N that satisfies the equation.

Input:

Input consists of two positive integer X & Y . (1<=X,Y<=2000000000)

Output:

You have to output minimum N.

Sample Input:

1 5
6 7

Sample Output:

5
7

Note: You have to give the total of all output for each input.
For the sample input set, you have to give
7+5 = 12. So answer is 12.

Download data sets

ANS-562252
my solution
#include<cstdlib>
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <ctime>
#include <cstring>
#include <cassert>
#include <sstream>
#include <iomanip>
#include <complex>
#include <queue>
#include <functional>
 
using namespace std;
 
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define last(a) int(a.size() - 1)
#define all(a) a.begin(), a.end()
#define seta(a,x) memset (a, x, sizeof (a))
#define I (int)
#define SZ(x) ((int) (x).size())
#define FE(i,x) for(typedef((x).begin() i=(x).begin();i!=(x).end();i++) 

typedef long long int  int64;
typedef unsigned long long int uint64;
typedef long double ldb;
typedef pair <int, int> pii;
typedef vector<int>vi;
typedef vector<string>vs;
 

 
template <class T> T sqr (T x) {return x * x;}

int gcd(int a,int b)
{
 if(b==0) return a;
 return gcd(b,a%b);
}

int main()
{
 int X,Y;
 int total=0;
 while(1)
 {
 cin>>X>>Y;
 int hcf=gcd(X,Y);
 int lcm=(X*Y)/hcf;
 total+=(lcm/X);
 cout<<total<<endl;
 }




return 0;
}


 

Programming Quest June 29, 2010

Filed under: C,C++ Programs — whoami @ 08:43
Tags: ,
If a number is the only number between a prime number and a square number it is
beprisque.
Such few numbers are: 2 3 8 10
2 is beprisque, because, 1 is a square and 3 is a prime number
3 is beprisque, because, 2 is prime and 4 is a square number
What's the 100th beprisque number ?

ANS-119026
From Young programmer.com

my solution (not optimized)

#include<cstdlib>
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <ctime>
#include <cstring>
#include <cassert>
#include <sstream>
#include <iomanip>
#include <complex>
#include <queue>
#include <functional>
 
using namespace std;
 
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define last(a) int(a.size() - 1)
#define all(a) a.begin(), a.end()
#define seta(a,x) memset (a, x, sizeof (a))
#define I (int)
#define SZ(x) ((int) (x).size())
#define FE(i,x) for(typedef((x).begin() i=(x).begin();i!=(x).end();i++) 

typedef long long int  int64;
typedef unsigned long long int uint64;
typedef long double ldb;
typedef pair <int, int> pii;
typedef vector<int>vi;
typedef vector<string>vs;
 

 
template <class T> T sqr (T x) {return x * x;}

int main()
{
 static int prime[1000009];
 static int sqr[1000009];
 for(int i=1;i<=1000;i++)
 sqr[i*i]=1;
 
 prime[1]=0;prime[2]=1;

 for(int i=3;i<=1000000;i=i+2)
 {
 int flag=1;
 for(int j=3;j<=sqrt(i);j++)
 {
 if(i%j==0) { flag=0;break;}
 else continue;
 }
 if(flag==1) prime[i]=1;
 }

 int count=0;
 for(int i=2;i<=120000;i++)
 {
 if((sqr[i-1]==1&&prime[i+1]==1)||(sqr[i+1]==1&&prime[i-1]==1)){cout<<i<<endl; ++count;}
 }

 cout<<count<<endl;
 


return 0;
}

here is the few BEPRISQUE number 2 3 8 10 24 48 80 82 168 224 226 360 440 442 728 840 1088 1090 1224 1368 1522 1848 2026 2208 2400 3024 3250 3720 3968 4760 5040 5624 5928 6562 7920 8648 9802 10608 11026 11448 12322 13688 13690 14160 14640 15130 16128 17160 18224 19320 21024 21610 24024 25920 28560 29242 29928 31328 33488 36480 42024 44520 47088 47962 49728 50626 53360 54288 56168 56170 57120 59050 61008 62002 64008 65026 66048 67080 70224 71288 74528 74530 77840 81224 85848 88210 89400 90600 91808 91810 95480 95482 97968 99224 103042 104328 112224 113568 116280 119026 100
 

Programming Quest June 29, 2010

Filed under: C,C++ Programs — whoami @ 07:09
Tags: ,

From Young Programmers site

Determine the number of n-bit sequences that contain no adjacent 1’s. For
example, for n = 3 the answer is 5 (sequences 000, 001, 010, 100, 101 are
acceptable while 011, 110, 111 are not).
Find the answer where n = 10

ANS-144

#include<cstdlib>
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <ctime>
#include <cstring>
#include <cassert>
#include <sstream>
#include <iomanip>
#include <complex>
#include <queue>
#include <functional>
 
using namespace std;
 
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define last(a) int(a.size() - 1)
#define all(a) a.begin(), a.end()
#define seta(a,x) memset (a, x, sizeof (a))
#define I (int)
#define SZ(x) ((int) (x).size())
#define FE(i,x) for(typedef((x).begin() i=(x).begin();i!=(x).end();i++) 

typedef long long int  int64;
typedef unsigned long long int uint64;
typedef long double ldb;
typedef pair <int, int> pii;
typedef vector<int>vi;
typedef vector<string>vs;
 

 
template <class T> T sqr (T x) {return x * x;}

int main()
{
 char s[1028];
 int count=0;
 for(int i=0;i<1024;i++)
 {
 int tmp=i;
 int j=0;
 if(i==0) {s[0]='0';s[1]='\0';}
 while(tmp>0)
 {
 int rem=tmp%2;
 s[j++]=rem+'0';
 tmp=tmp/2;
 }
 if(i!=0)
 s[j]='\0';
 //printf("%s\n",s);

 if(!strstr(s,"11")) ++count;   
 }

 cout<<count<<endl;

return 0;
}


 

Programming Question June 29, 2010

Filed under: C,C++ Programs — whoami @ 05:57
Tags:

A number has 6 different digits. If the last digit is moved to the front, then a new number is formed which is exaclty 5 times the old number. With which number did we start?

my solution


#include<cstdlib>
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <ctime>
#include <cstring>
#include <cassert>
#include <sstream>
#include <iomanip>
#include <complex>
#include <queue>
#include <functional>

using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define last(a) int(a.size() - 1)
#define all(a) a.begin(), a.end()
#define seta(a,x) memset (a, x, sizeof (a))
#define I (int)
#define SZ(x) ((int) (x).size())
#define FE(i,x) for(typedef((x).begin() i=(x).begin();i!=(x).end();i++)

typedef long long int  int64;
typedef unsigned long long int uint64;
typedef long double ldb;
typedef pair <int, int> pii;
typedef vector<int>vi;
typedef vector<string>vs;



template <class T> T sqr (T x) {return x * x;}

int main()
{
 char s[15];
 int count[10];
 for(int i=102345;i<=999999;i++)
 {
 sprintf(s,"%d",i);
 for(int k=0;k<10;k++)
 count[k]=0;
 int flag=1;
 for(int j=0;j<strlen(s);j++){
 count[s[j]-'0']++;
 if(count[s[j]-'0']>=2) {flag=0;break;}
 else continue;
 }
 if(flag==1)
 {
 char str[15];
 str[0]=s[strlen(s)-1];
 for(int j=0;j<strlen(s)-1;j++)
 str[j+1]=s[j];
 str[strlen(s)]='\0';
 int num=atoi(str);
 if(num==5*i) printf("%d\n",i);
 }
 }
return 0;
}

//Answer is 142857


 

Fibonacci Or Not June 29, 2010

Filed under: C,C++ Programs — whoami @ 05:13
Tags: ,

The condition to check whether the given number is fibonacci or not. Or say printing numbers which are fibonacci ..

Condition :

N is a Fibonacci number if and only if 5 N2 + 4 or 5 N2 – 4 is a square number.
This was given by I Gessel in 1972. Here is the link
program in C++
</div>
<div>//checking whether the number is fibonacci or not
#include<cstdlib>
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <ctime>
#include <cstring>
#include <cassert>
#include <sstream>
#include <iomanip>
#include <complex>
#include <queue>
#include <functional>

using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define last(a) int(a.size() - 1)
#define all(a) a.begin(), a.end()
#define seta(a,x) memset (a, x, sizeof (a))
#define I (int)
#define SZ(x) ((int) (x).size())
#define FE(i,x) for(typedef((x).begin() i=(x).begin();i!=(x).end();i++)

typedef long long int  int64;
typedef unsigned long long int uint64;
typedef long double ldb;
typedef pair <int, int> pii;
typedef vector<int>vi;
typedef vector<string>vs;

template <class T> T sqr (T x) {return x * x;}

int main()
{
 int count=0;
 for(int64 i=0;i<1000000000/*2147483639*/;i++)
 {
 int64 N=i;
 int64 tmp1=5*N*N+4,tmp2=5*N*N-4;//whether the number is fibonacci or not
 ldb t1=(ldb)sqrt((ldb)tmp1);
 ldb t2=(ldb)sqrt((ldb)tmp2);
 int64 tt1=(int64)t1,tt2=(int64)t2;
 if(t1==(ldb)tt1||t2==(ldb)tt2){
 printf("%d %lld\n",++count,i);
 }
 }

return 0;
}</div>
<div></div>
<div>

Here is the few Fibonacci numbers
s.no  fib
1 0
2 1
3 2
4 3
5 5
6 8
7 13
8 21
9 34
10 55
11 89
12 144
13 233
14 377
15 610
16 987
17 1597
18 2584
19 4181
20 6765
21 10946
22 17711
23 28657
24 46368
25 75025
26 121393
27 196418
28 317811
29 514229
30 832040
31 1346269
32 2178309
33 3524578
34 5702887
35 9227465
36 14930352
37 24157817
38 39088169
39 63245986
40 102334155
41 165580141
42 267914296
43 433494437
44 701408733

 

UVA Contest from BUBT, Bangladesh June 29, 2010

Filed under: C,C++ Programs,UVA — whoami @ 02:30
Tags: ,

LINK

Solved 2 problems A and B during the contest.

Problem A Argentina

#include<cstdlib>

#include <cstdio>

#include <iostream>

#include <vector>

#include <cmath>

#include <algorithm>

#include <string>

#include <set>

#include <map>

#include <ctime>

#include <cstring>

#include <cassert>

#include <iomanip>

#include <complex>

#include <queue>

#include <functional>

using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)

#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)

#define pb push_back

#define mp make_pair

#define fs first

#define sc second

#define last(a) int(a.size() - 1)

#define all(a) a.begin(), a.end()

#define seta(a,x) memset (a, x, sizeof (a))

#define I (int)

#define SZ(x) ((int) (x).size())

//#define FE(i,x) for(typedef(x).begin() i=(x).begin();i!=(x).end();i++)

typedef long long int  int64;

typedef unsigned long long int uint64;

typedef long double ldb;

typedef pair <int, int> pii;

typedef vector<int>vi;

typedef vector<string> vs;

template <class T> T sqr (T x) {return x * x;}

int main()

{

  int cases;

  cin>>cases;

  char s[100];

  vector<string>vs;

  int a[11],b[11];

  int c=0;

  while(cases--)

  {

  vs.clear();

  for(int i=0;i<10;i++)

  {

    scanf("%s%d%d",s,&a[i],&b[i]);

    string str=(string)(s);

    vs.pb(str);

  }

  for(int i=0;i<10;i++)

  {

    for(int j=0;j<10;j++)

    {

      if(a[i]<a[j])

      {

        swap(a[i],a[j]);swap(vs[i],vs[j]);swap(b[i],b[j]);

      }

      else if(a[i]==a[j])

      {

        if(b[i]>b[j])

        {

          swap(b[i],b[j]);swap(vs[i],vs[j]);swap(a[i],a[j]);

        }

        else if(b[i]==b[j])

        {

           if(vs[i]>vs[j])

           {

             swap(b[i],b[j]);swap(vs[i],vs[j]);swap(a[i],a[j]);

           }

        }//else

      }//else

    }//for

  }//for

   sort(vs.begin(),vs.begin()+5);

   sort(vs.begin()+5,vs.end());

  printf("Case %d:\n",++c);

  printf("(");

  for(int i=5;i<9;i++)

    cout<<vs[i]<<", ";

  cout<<vs[9]<<")\n";

  printf("(");

  for(int i=0;i<4;i++)

    cout<<vs[i]<<", ";

  cout<<vs[4]<<")\n";

  }

return 0;

}</pre>
<pre>

Problem B Bafana Bafana


#include<cstdlib>
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <ctime>
#include <cstring>
#include <cassert>
#include <iomanip>
#include <complex>
#include <queue>
#include <functional>

using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define last(a) int(a.size() - 1)
#define all(a) a.begin(), a.end()
#define seta(a,x) memset (a, x, sizeof (a))
#define I (int)
#define SZ(x) ((int) (x).size())
#define FE(i,x) for(typedef(x).begin() i=(x).begin();i!=(x).end();i++)

typedef long long int  int64;
typedef unsigned long long int uint64;
typedef long double ldb;
typedef pair <int, int> pii;
typedef vector<int>vi;
typedef vector<string>vs;



template <class T> T sqr (T x) {return x * x;}

int main()
{
 int cases;
 cin>>cases;
 int N,K,P;
 int i=0;
 while(cases--)
 {
 cin>>N>>K>>P;
 int tmp=(K+P)%N;
 printf("Case %d: ",++i);
 if(tmp==0) cout<<N<<endl;
 else cout<<tmp<<endl;
 }


return 0;
}

 

UVA Contest from Dinajpur, Bangladesh June 29, 2010

Filed under: C,C++ Programs,UVA — whoami @ 02:20
Tags: ,

LINK
I solved a single problem during this UVA contest
F Horror Dash

#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
using namespace std;

int main()
{
  int cases;
  cin>>cases;
  int i=0;
  while(cases--)
  {
     int n;
     cin>>n;
     cout<<"Case "<<++i<<": ";
     int max=-1;
     while(n--){
      int item;
      cin>>item;
      if(item>max) max=item;
      }
    cout<<max;
    if(cases!=0) printf("\n");
  }


return 0;
}

 

Google interview experienced thru www….. June 15, 2010

Filed under: GOOGLE — whoami @ 00:10
Tags: ,

Here goes the link

 

TJU 3181. Stock Exchange June 10, 2010

Filed under: C,C++ Programs,TJU — whoami @ 12:43
Tags: ,

TJU 3181. Stock Exchange
ACCEPTED

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;

int main()
{
  char s[100],s1[100],s2[100];
  int i,j,k;
  
  vector<double>price;
 
  vector<string>agent,buysell;
  while(1){
   int n;
   scanf("%d%s",&n,s);
   string str=s,str1;
   double d;
   if(n==0&&str=="END") break;
     agent.clear();buysell.clear();price.clear();
      for(int i=0;i<n;i++){
        scanf("%s%s%lf",s1,s2,&d);
        str1=s1;agent.push_back(str1);
        str1=s2;buysell.push_back(str1);
        price.push_back(d);
        }
       vector< vector<string> > v;
       vector<string> tmp;
       vector< vector<string> >::iterator x;
       //for(x=v.begin();x<v.begin();x++)
         // (*x).clear();
       v.clear(); 
       tmp.clear();

       vector<string>::iterator it1,it2,it3,it4;
       it3=buysell.begin();it4=buysell.begin();
       vector<double>::iterator it5,it6;
       it5=price.begin();it6=price.begin();
      for(it1=agent.begin();it1<agent.end();it1++,it3++,it5++){
              //cout<<"yes";
              tmp.clear();
              int flag=0;
              for(it2=agent.begin(),it4=buysell.begin(),it6=price.begin();it2<agent.end();it2++,it4++,it6++){
                   if(it1!=it2){
                          if(*it3!=*it4){
                              if(*it3=="buy"){
                                      if(*it6<=*it5){
                                        tmp.push_back(*it2);
                                        flag=1;
                                        }
                                   }
                               else if(*it3=="sell"){
                                           if(*it5<=*it6){
                                              tmp.push_back(*it2);
                                              flag=1;
                                              }
                                   }
                               }
                          }
                    }
                 if(flag==0) {tmp.push_back("NO-ONE");
                              v.push_back(tmp);
                             }
                 else
                           v.push_back(tmp);
               }  
                    
         printf("%s\n",s); 
        vector<string>::iterator it=agent.begin();
         vector< vector<string> >::iterator ii;
         vector<string>::iterator ii2;
         ii=v.begin();                                   
         for(int i=0;i<n;i++,it++,ii++){
           cout<<*it<<":";
           for(ii2=(*ii).begin();ii2<(*ii).end();ii2++){
              cout<<" "<<(*ii2);
              }
            cout<<endl;
           }
       
       }

return 0;
}


 

 
Follow

Get every new post delivered to your Inbox.