//P1597 语句解析
//#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
#include <sstream>
#define inf 0x3f3f3f3f
#define eps 1e-6
using namespace std;
#define clr(x) memset(x,0,sizeof((x)))
const int maxn = 1e4+1;//2e6+1
#define MAX(a,b,c) ((a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c)))
#define _max(a,b) ((a) > (b) ? (a) : (b))
#define _min(a,b) ((a) < (b) ? (a) : (b))
#define _for(a,b,c) for(int a = b;a<c;a++)
int a,b,c;
int main()
{
#ifdef LOCAL
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
#endif
//方法一 略微繁琐
// char s[300];
// scanf("%s",s);
// int len = strlen(s);
// for(int i = 0;i<len;i = i+5) {
// switch(s[i]) {
// case 'a':if(isdigit(s[i+3]))a = s[i+3]-'0';
// else if(s[i+3]=='a')a = a;
// else if(s[i+3]=='b')a = b;
// else if(s[i+3]=='c')a = c;
// break;
// case 'b':if(isdigit(s[i+3]))b = s[i+3]-'0';
// else if(s[i+3]=='a')b = a;
// else if(s[i+3]=='b')b = b;
// else if(s[i+3]=='c')b = c;
// break;
// case 'c':if(isdigit(s[i+3]))c = s[i+3]-'0';
// else if(s[i+3]=='a')c = a;
// else if(s[i+3]=='b')c = b;
// else if(s[i+3]=='c')c = c;
// break;
// }
// }
//方法二
char x,y;
int arr[3];
clr(arr);
while(scanf("%c:=%c;",&x,&y)==2) {
arr[x-'a'] = (isdigit(y) ? y - '0':arr[y-'a']);
}
_for(i,0,3) cout<<arr[i]<<" ";
return 0;
}
洛谷 P1597 语句解析 题解 (字符串C/C++)
猜你喜欢
转载自blog.csdn.net/Jason__Jie/article/details/112849593
今日推荐
周排行