// Poj for the second top embedded cup preliminary round
// Question
# Include <stdio. h>
Int A3, B3;
Void reduce ()
{
While (A3% 2 = 0 & B3 % 2 = 0)
{A3/= 2; B3/= 2 ;}
While (A3% 3 = 0 & B3 % 3 = 0)
{A3/= 3; B3/= 3 ;}
While (A3% 5 = 0 & B3 % 5 = 0)
{A3/= 5; B3/= 5 ;}
While (A3% 7 = 0 & B3 % 7 = 0)
{A3/= 7; B3/= 7 ;}
}
Int main ()
{
Int A1, B1, A2, B2;
Char option;
Char inputstr [10];
While (scanf ("% s", & inputstr )! = EOF)
{
A1 = inputstr [0]-'0 ';
B1 = inputstr [2]-'0 ';
Option = inputstr [3];
A2 = inputstr [4]-'0 ';
B2 = inputstr [6]-'0 ';
B3 = b1 * B2;
If (option = '+ ')
A3 = A1 * B2 + A2 * B1;
Else
A3 = A1 * b2-a2 * B1;
If (A3 = 0)
Printf ("0 \ n ");
Else
{
Reduce ();
If (B3! = 1)
Printf ("% d/% d \ n", A3, B3 );
Else
Printf ("% d \ n", A3 );
}
}
Return 0;
}
// Question B
# Include <stdio. h>
Int main ()
{
Int A, B;
While (scanf ("% d", & A, & B )! = EOF)
{
Printf ("% d \ n", a % B );
}
Return 0;
}
// Question C
# Include <stdio. h>
# Include <string. h>
Int main ()
{
Char inputstr [1005] = {0 };
Char out [1005] = {0 };
Int Len, I, J;
While (fgets (inputstr, 1000, stdin )! = 0) // read a row (including spaces)
{
I = 0; j = 0;
Len = strlen (inputstr );
While (I <len-1) // Since using fgets will save '\ n' in the end of the string, so do not last
{
If (inputstr [I] = 'y' & I + 2 <Len)
{
If (inputstr [I + 1] = 'O' & inputstr [I + 2] = 'U ')
{
Out [J ++] = 'W ';
Out [J ++] = 'E ';
I = I + 3;
}
Else
{
Out [J ++] = inputstr [I ++];
}
}
Else
{
Out [J ++] = inputstr [I ++];
}
}
Out [J] = '\ 0 ';
Printf ("% s \ n", out );
}
Return 0;
}
// Question d
// For high-precision questions, use Longlong and separate them into three sections.
# Include <stdio. h>
# Include <string. h>
# define weinum 1000000000000
long a [105] [3];
int status [105];
void calcu (int n)
{
a [n] [0] = A [n-1] [0] + A [N-2] [0] + A [n-3] [0];
if (a [n] [0]/weinum> 0)
{
a [n] [1] = a [n] [0]/weinum;
a [n] [0] % = weinum;
}< br> if (a [n-1] [1]> 0)
{
a [n] [1] + = A [n-1] [1] + A [N-2] [1] + A [n-3] [1];
if (a [n] [1]/weinum> 0)
{< br> a [n] [2] = a [n] [1]/weinum;
a [n] [1] % = weinum;
}< br> if (a [n-1] [2]> 0)
a [n] [2] + = A [n-1] [2] + A [N-2] [2] + A [n-3] [2];
}< BR >}
Void fun (int n)
{
If (n = 0 | n = 1 | n = 2)
;
Else if (status [N] = 0)
{
Fun (n-3 );
Fun (n-2 );
Fun (n-1 );
Calcu (N );
Status [N] = 1;
}
Return;
}
Int main ()
{
Int A0, A1, A2;
Int I;
Long long temp;
Int count;
While (scanf ("% d", & A0, & A1, & A2 )! = EOF)
{
Memset (status, 0, sizeof (Status ));
Memset (A, 0, sizeof ());
A [0] [0] = A0;
A [1] [0] = A1;
A [2] [0] = a2;
Fun (99 );
If (A [99] [2]> 0)
Printf ("% LLD", a [99] [2]);
If (A [99] [1]> 0)
{
If (A [99] [2]> 0)
{
Count = 0;
Temp = A [99] [1];
While (temp> 0)
{
Temp/= 10;
Count ++;
}
For (I = 0; I <12-count; I ++)
Printf ("0 ");
}
Printf ("% LLD", a [99] [1]);
}
If (A [99] [1]> 0 | A [99] [2]> 0)
{
Count = 0;
Temp = A [99] [0];
While (temp> 0)
{
Temp/= 10;
Count ++;
}
For (I = 0; I <12-count; I ++)
Printf ("0 ");
}
Printf ("% LLD \ n", a [99] [0]);
}
Return 0;
}