http://acm.sgu.ru/problem.php?contest=0&problem=359
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
using namespace std;
int num[4] = {0,0,0,0};
int *a, *b, *c, *d, *f;
void find(char ss)
{
switch(ss)
{
case 'a' : f = a ; break;
case 'b' : f = b ; break;
case 'c' : f = c ; break;
case 'd' : f = d ; break;
}
};
int main()
{
a = f = &(num[0]);
b = &(num[1]), c = &(num[2]), d = &(num[3]);
string str;
int t;
scanf("%d",&t);
while(t--)
{
cin>>str;
if(str[0] == 'w')
{
find(str[8]);
cout<< *f<<endl;
}
else
{
if(str[1] == ':')
{
find(str[3]);
switch(str[0])
{
case 'a' : a = f ; break;
case 'b' : b = f ; break;
case 'c' : c = f ; break;
case 'd' : d = f ; break;
}
}
else if(str[1] == '^' )
{
if(isdigit(str[4]))
{
find(str[0]);
*f = str[4] - '0';
}
else if(isalpha(str[4]))
{
find(str[3]);
switch(str[0])
{
case 'a' : *a = *f ; break;
case 'b' : *b = *f ; break;
case 'c' : *c = *f ; break;
case 'd' : *d = *f ; break;
}
}
}
}
}
return 0;
}