Problem 0024 : Physical Experiments
#include <iostream>
using namespace std;
int main(void)
{
double v, t, y, n;
while( cin >> v ){
t = v/9.8;
y = 4.9*t*t;
for( n=0; 5*n-5<y; n++ );
cout << n << endl;
}
return 0;
}
Problem 0025 : Hit and Blow
#include <iostream>
using namespace std;
int main(void)
{
int a[4], b[4];
int hit, blow;
int i, j;
char check;
while(1){
hit = blow = 0;
for( i=0; i<4; i++ ){
cin >> a[i];
}
if( cin.eof() ) break;
for( i=0; i<4; i++ ){
cin >> b[i];
if( a[i] == b[i] ){
hit++;
} else {
for( j=0; j<4; j++ ){
if( i == j ) continue;
if( a[j] == b[i]){
blow++;
break;
}
}
}
}
cout << hit << " " << blow << endl;
}
return 0;
}
Problem 0026 : Dropping Ink
#include <iostream>
#include <string>
#include <limits.h>
using namespace std;
int toInt( string str ){
int n = 0;
for( int i=0; i<str.size() && isdigit(str[i]); i++ ){
n = n*10 + (str[i]-'0');
}
return n;
}
void S( int p[10][10], int x, int y )
{
p[x][y]++;
if( x+1 < 10 ) p[x+1][y]++;
if( x-1 >= 0 ) p[x-1][y]++;
if( y+1 < 10 ) p[x][y+1]++;
if( y-1 >= 0 ) p[x][y-1]++;
return;
}
void M( int p[10][10], int x, int y )
{
S( p, x, y );
if( x+1 < 10 && y+1 < 10 ) p[x+1][y+1]++;
if( x-1 >= 0 && y-1 >= 0 ) p[x-1][y-1]++;
if( x-1 >= 0 && y+1 < 10 ) p[x-1][y+1]++;
if( x+1 < 10 && y-1 >= 0 ) p[x+1][y-1]++;
return;
}
void L( int p[10][10], int x, int y )
{
M( p, x, y );
if( x+2 < 10 ) p[x+2][y]++;
if( x-2 >= 0 ) p[x-2][y]++;
if( y+2 < 10 ) p[x][y+2]++;
if( y-2 >= 0 ) p[x][y-2]++;
return;
}
void calc( int p[10][10] )
{
int max;
int cnt = 0;
max = INT_MIN;
for( int i=0; i<10; i++ ){
for( int j=0; j<10; j++ ){
if( p[i][j] > max )
max = p[i][j];
if( p[i][j] == 0 )
cnt++;
}
}
cout << cnt << endl;
cout << max << endl;
}
**Problem 0026 : Dropping Ink
int main(void)
{
int p[10][10] = {0};
int x, y, size;
string input, work;
while( cin >> input ){
work.clear();
work = input.substr( 0, input.find( "," ) );
input.erase( 0, input.find( "," )+1 );
x = toInt(work);
work = input.substr( 0, input.find( "," ) );
input.erase( 0, input.find( "," )+1 );
y = toInt(work);
work = input.substr( 0, input.size() );
size = toInt(work);
if( size == 1 ) S( p, x, y );
if( size == 2 ) M( p, x, y );
if( size == 3 ) L( p, x, y );
}
calc(p);
return 0;
}