Problem 0011 : Drawing Lots
#include <iostream>
#include <ctype.h>
using namespace std;
int main(void)
{
int num[31];
for( int i=0; i<=30; i++ )
num[i] = i;
int w, n;
char ch;
cin >> w;
cin >> n;
cin.get(ch);
int i, j; int a[2];
for( i=0; i<n; i++ ){
a[0] = a[1] = 0;
for( j=0; j<2; j++ ){
cin.get(ch);
while( isdigit(ch) ){
a[j] = a[j]*10 + (ch-'0');
cin.get(ch);
}
}
int tmp;
tmp = num[a[0]];
num[a[0]] = num[a[1]];
num[a[1]] = tmp;
}
for( i=1; i<=w; i++ )
cout << num[i] << endl;
return 0;
}
Problem 0013 : Switching Railroad Cars
#include <iostream>
#include <stack>
using namespace std;
int main(void)
{
stack<int> cars;
int input;
while( cin >> input ){
if( input == 0 ){
cout << cars.top() << endl;
cars.pop();
} else {
cars.push(input);
}
}
return 0;
}
Problem 0014 : Integral
#include <iostream>
using namespace std;
int main(void)
{
int d;
int i, j;
unsigned long int s;
while( cin >> d ){
s = 0;
for( i=1; i*d<600; i++ )
s += d*d*d*i*i;
cout << s << endl;
}
return 0;
}