Saturday, 25 August 2012

PLAY WITH DATES


Play with dates


Problem Statement:

Given the date, month and year, find the day.

Input Specification:

The first line consists of an integer t, the number of test cases. Then for each test case there are three integers the date, month and year.

Output Specification:

For each test case print the day in words in a separate line(The first character should be caps followed by small letters).

Input Constraints:

1<=t<=100

Date/month/year >= 11/1/2012

Date/month/year<=31/12/3000

The given date will always be a valid date

Sample Input:

3

11 1 2012

12 1 2012

13 1 2012

Sample Output:

Wednesday

Thursday

Friday


SOLUTION--------------




#include
int main()
{
        unsigned long long int t,i,day,month,year,total_days,Y,M;
        scanf("%llu",&t);
        while(t--)
        {
                int arr[13];
                arr[1]=31,arr[2]=28,arr[3]=31,arr[4]=30,arr[5]=31,arr[6]=30,arr[7]=31,arr[8]=31,arr[9]=30,arr[10]=31,arr[11]=30,arr[12]=31;
                total_days=0;
                scanf("%llu %llu %llu",&day,&month,&year);
                Y=1900,M=1;
                if(year>1900)
                {
                        while(Y
                        {
                        if((Y%4==0&&Y%100!=0)||Y%400==0)
                        {
                                total_days+=366;
                        }
                        else{
                                total_days+=365;
                        }
                        Y=Y+1;
                        }
                }
                        if(month>1){
                        for(M=1;M
                        {
                                if(M==2)
                                {
                                if((Y%4==0&&Y%100!=0)||Y%400==0){
                                total_days+=29;
                                }
                                }
                                else
                                total_days+=arr[M];
                        }
                        }
                        total_days+=day;
                    
                        i=total_days%7;
                
                        if(i==0)
                                printf("Sunday\n");
                        if(i==1)
                                printf("Monday\n");
                        if(i==2)
                                printf("Tuesday\n");
                        if(i==3)
                                printf("Wednesday\n");
                        if(i==4)
                                printf("Thursday\n");
                        if(i==6)
                                printf("Saturday\n");
                        if(i==5)
                                printf("Friday\n");
        }
        return 0;
}



Saturday, 11 August 2012

PIZZA


Saturday, 11 August 2012
PIZZA


SPOJ Problem Set (classical)


7169. Pizza


Problem code: EGYPIZZA




Abotrika is having a party because his team won the african cup so he is inviting his friends to eat some pizza.

Unfortunately,Abotrika's friends can't eat an entire pizza but all of them know exactly how much pizza

they can eat and insist on getting the exact amount of pizza but Abotrika eats one complete pizza 
and all of them wants his amount of pizza in one slice.


Their requests break down to three different pizza slices-either one quarter or a half or three quarters of pizza.

write a program that will help Abotrika to find out what is the minimal number of pizzas he has to order so that

everyone gets exact amount of pizza they want.


Input

First line contains an integer N, 0<=N<=10,000 , number of friends.

In each of next N lines there is amount of pizza that each of Abotrika's friends wants to eat,that

is the fraction 1/4 , 1/2 or 3/4.


Output

In the first and only line you should write the minimal number of pizzas Abotrika has order don't forget to order

one complete pizza for Abotrika


Example

Input:
3

1/2

3/4

3/4

Output:
4

Input:

5

1/2

3/4

1/2

1/4

1/4

Output:

4




#include
int main()
{
        int t,a,b,i,half=0,quarter=0,third_quarter=0,pizza=0;
        char c;
        scanf("%d",&t);
        for(i=0;i
        {
                scanf("%d%c%d",&a,&c,&b);
                if(a==1&&b==2)
                        half=half+1;
                else if(a==1&&b==4)
                        quarter=quarter+1;
                else
                        third_quarter=third_quarter+1;
        }
        if(quarter==0)
        {
                pizza=third_quarter+(half/2)+(half%2);
        }
        else{
                if(quarter<=third_quarter)
                        pizza=third_quarter+(half/2)+(half%2);
                if(quarter>third_quarter)
                {
                        pizza+=third_quarter;
                        quarter=quarter-third_quarter;
                        if(quarter>2*half)
                        {
                                pizza+=half+(2*half-quarter);
                        }
                        else if(quarter==2*half)
                        {
                                pizza+=half;
                        }
                        else if(quarter<2 font="font" half="half">
                        {
                                int half1;
                                half1=(quarter/2)+(quarter%2);
                                half=half-half1;
                                pizza+=half1+(half/2)+(half%2);
                        }
                }
        }
        printf("%d\n",pizza+1);
        return 0;
}  

Friday, 10 August 2012

ADD TWO NUMBERS WITHOUT INCREMENT ,DECREMENT,AIRTHMETIC

EXAMPLE:
For adding x=6 and y=10

 
          6            ----> 0 1 1 0
          10           ----> 1 0 1 0
                       ------------------
(1) XOR(6^10)          ----> 1 1 0 0            carry(6&10) ----> 0 0 1 0
(2) carry(6&10) << 1   ----> 0 1 0 0
                       ------------------
(3) [1] OR [2]         ----> 1 1 0 0  = ( 12)  carry(12&4)  ----> 0 1 0 0 
(4) carry(12&4) << 1   ----> 1 0 0 0 
                       -------------------
[3] OR [4]             ----> 1 0 0 0 = (16)

Code:
int Add(int x, int y)
{ 
    while (y != 0)
    {
        int carry = x & y; 
        x = x ^ y;
        y = carry << 1;
    }
    return x;
}

Wednesday, 8 August 2012

THANKS TO ALL VISITORS

Thnaks to all visitors who visited my blogs :)
Now view pages of blogs go to 6000+ all credit goes to my blog visitors thanks to all of you :)

Monday, 6 August 2012

SUBARRAYS


SPOJ Problem Set (classical)

10582. subarrays

Problem code: ARRAYSUB

Given an array and an integer k, find the maximum for each and every contiguous subarray of size k.

Input

the number n denoting number of elements in the array then after a new line we have the numbers of the array
and then k in a new line
n<10 p="p"> k<10 p="p"> 1 <= k <=n
and each element of the array is between 0 and 10^6

Output

print the output array

Example

Input:
9
1  2  3  1  4  5  2  3  6
3
Output:
3 3 4 5 5 5 6









SOLUTION------------------------------------------------------------------------------------------

#include
int main()
{
         long long int n,k,i,j,max;
        scanf("%lld",&n);
        long long int arr[n];
        for(i=0;i        {
                scanf("%lld",&arr[i]);
        }
        scanf("%lld",&k);
        max=arr[0];
        for(i=0;i        {
                if(i==0 || max==arr[i-1]){
                max=arr[i];
                for(j=i;j                        if(arr[j]>max)
                                max=arr[j];
                }
                }
                else{
                        if(arr[i+k-1]>max)
                                max=arr[i+k-1];
                }
               
                printf("%lld ",max);
                if(i+k>=n){
                        break;
                }
        }
        return 0;
}

Saturday, 4 August 2012

IN DANGER


Saturday, 4 August 2012

 IN DANGER SPOJ 

Problem Set (classical) 1786.

 In Danger Problem code: DANGER Flavius Josephus and 40 fellow rebels were trapped by the Romans. His companions preferred suicide to surrender, so they decided to form a circle and to kill every third person and to proceed around the circle until no one was left. Josephus was not excited by the idea of killing himself, so he calculated the position to be the last man standing (and then he did not commit suicide since nobody could watch). We will consider a variant of this "game" where every second person leaves. And of course there will be more than 41 persons, for we now have computers. You have to calculate the safe position. Be careful because we might apply your program to calculate the winner of this contest! Input Specification The input contains several test cases. Each specifies a number n, denoting the number of persons participating in the game. To make things more difficult, it always has the format "xyez" with the following semantics: when n is written down in decimal notation, its first digit is x, its second digit is y, and then follow z zeros. Whereas 0<=x,y<=9, the number of zeros is 0<=z<=6. You may assume that n>0. The last test case is followed by the string 00e0. Output Specification For each test case generate a line containing the position of the person who survives. Assume that the participants have serial numbers from 1 to n and that the counting starts with person 1, i.e., the first person leaving is the one with number 2. For example, if there are 5 persons in the circle, counting proceeds as 2, 4, 1, 5 and person 3 is staying alive. Sample 
Input 
05e0 
01e1 
42e0 
66e6 
00e0 
Sample Output 
21 
64891137


SOLUTION-------------------------------------------------------------------------

#include
#include
int function(long long int);
int main(){        
int x,y,z;        
char str[6];        
scanf("%s",str);        
x=str[0]-'0';        
y=str[1]-'0';        
z=str[3]-'0';        
//printf("%d %d %d",x,y,z);        
long long int temp,value,value1,value2,k,ans;                 while(x!=0||y!=0||z!=0)        
 {                 
temp=pow(10,z);                 
value=(x*10+y)*temp;                 
value1=function(value);                 
value2=value-value1;                 
ans=value2*2+1;                 
printf("%lld\n",ans);                                  scanf("%s",str);                 
x=str[0]-'0';                 
y=str[1]-'0';                 
z=str[3]-'0';           
  }         
return 0; }
       
int function( long long int x)    
{    
long long int y,p,h=1;    
p=pow(2,h);    
while(p<=x)    
{   
 h=h+1;    
p=pow(2,h);    
}    
y=pow(2,h-1);        
return y;    

MUSICAL CHAIRS


4557. MUSICAL CHAIRS

PROBLEM CODE: ANARC08F




 In the traditional game of Musical Chairs, N + 1 children run around N chairs (placed in a circle) as long as music is playing. The moment the music stops, children run and try to sit on an available chair. The child still standing leaves the game, a chair is removed, and the game continues with N children. The last child to sit is the winner.

In an attempt to create a similar game on these days' game consoles, you modify the game in the following manner: N Children are seated on N chairs arranged around a circle. The chairs are numbered from 1 to N . Your program pre-selects a positive number D . The program starts going in circles counting the children starting with the first chair. Once the count reaches D , that child leaves the game, removing his/her chair. The program starts counting again, beginning with the next chair in the circle. The last child remaining in the circle is the winner.
For example, consider the game illustrated in the figure above for N = 5 and D = 3 . In the figure, the dot indicates where counting starts and × indicates the child leaving. Starting off, child #3 leaves the game, and counting restarts with child #4. Child #1 is the second child to leave and counting restart with child #2 resulting in child #5 leaving. Child #2 is the last to leave, and child #4 is the winner. Write a program to determine the winning child given both N and D .

Input

Your program will be tested on one or more test cases. Each test case specifies two positive integers N and D on a single line, separated by one or more spaces, where N, D < 1,000,000 .

The last line of the input file contains two 0's and is not part of the test cases.

Output

For each test case, write the winner using the following format:

N D W

Where N and D are as above, is a space character, and W is the winner of that game.

Example

Input:
5 3
7 4
0 0

Output:
5 3 4
7 4 2




SOLUTION-----------------------------------------------------------------------//

#include
int main()
{
        long long int N,K,W,i;
        scanf("%lld",&N);
        scanf("%lld",&K);
        while(N!=0||K!=0)
        {
                W=0;
    
                for(i=2;i<=N;i++)
                {       
                        W=(W+K)%i;
                }
                printf("%lld %lld %lld\n",N,K,W+1);
               
                scanf("%lld",&N);
                scanf("%lld",&K);
        }
        return 0;
}