【C语言】利用switch解题
  • 板块P1597 语句解析
  • 楼主UGIWBGS
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/10/26 10:30
  • 上次更新2024/10/26 10:33:37
查看原帖
【C语言】利用switch解题
1538946
UGIWBGS楼主2024/10/26 10:30
//这题我们只需要找变量a,b,c和对应的变量值的位置进行判断即可
//如果输出是字符的话能代码还能简略些,这里我不清楚输出要求就化成int型了
int main(){
    char str[256];
    scanf("%s",str);
    int a=0,b=0,c=0;
    for(int i=0;i<strlen(str)-4;i+=5){
        int temp;
        switch(str[i+3]){
            case 'a':
                temp=a;
                break;
            case 'b':
                temp=b;
                break;
            case 'c':
                temp=c;
                break;
            default:
                temp=str[i+3]-'0';
                break;
        }
        if(str[i]=='a')a=temp;
            else if(str[i]=='b')b=temp;
                else c=temp;
    }
    printf("%d %d %d",a,b,c);
    
}
2024/10/26 10:30
加载中...