zoukankan      html  css  js  c++  java
  • 6-3 矩阵链成 uva 442

    较为简单的栈题

    思路比较好 

    一次ac

    1、char word ;word=A;直接  a[word]=xxxx,不用 a[‘word’]=xxxx

    #include<bits/stdc++.h>
    
    using namespace std;
    
    
    struct aaa
    {
    
        int x;
        int y;
    
    }a[1000];
    
    int main()
    {
       stack<aaa>k;
      int n;
      cin>>n;getchar();
      for(int i=1;i<=n;i++)
      {
          char word;cin>>word;
          cin>>a[word].x>>a[word].y;
    
      }
    
        string s;
        while(getline(cin,s))
        {
            if(s=="")continue;
            if(s.size()==1){printf("0
    ");continue;}
            int sum=0;int ok=1;
            for(int i=0;i<s.size();i++)
            {
                if(isalpha(s[i])){k.push(a[ s[i] ]);}
                else if(s[i]==')')
                {
                    struct aaa x1=k.top();k.pop();
                    struct aaa x2=k.top();k.pop();
                    struct aaa x3;
                    if(x1.x!=x2.y){ok=0;printf("error
    ");break;}
                    sum+=x1.x*x1.y*x2.x;
                    x3.x=x2.x;x3.y=x1.y;
                    k.push(x3);
    
    
                }
    
    
            }
            if(ok)printf("%d
    ",sum);
    
    
        }
    
    
    
    
    
    
    
    
    
        return 0;
    }
    View Code
  • 相关阅读:
    Zookeeper环境搭建
    Zookeeper介绍
    相关错题
    数据库前三章测试题
    数据库相关练习题
    SQL语句操作数据
    用表组织数据
    创建和管理SQL Server数据库
    登陆数据库
    C#部分试题实例
  • 原文地址:https://www.cnblogs.com/bxd123/p/10285828.html
Copyright © 2011-2022 走看看