new 第五届,化学实验(吉林大学的map和vector可以打印)


看完了这个代码,发现,其实这个化学反应的过程并没有很复杂

还是那种一个一个的方程式走,没有使用所谓的拓扑排序。

map vector可以打印一下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
   
#include <map>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
using namespace std;
  
char ch[600];
vector< int > vec1[405],vec2[405];
map<string, int > m;
int cnt=1;
bool b[2000],ne[2000],flag[405]; 
  
void deal( char *ch, int i)
{
     char str[15];
     int len=0,f=0;
     while ( 1 ){
         sscanf (ch+len, "%[^+=]" , str); 
         len += strlen (str);
         if ( !m[str] )  m[str] = cnt++;
  
         if ( !f ) vec1[i].push_back( m[str] );
         else vec2[i].push_back(m[str]);
  
         if ( *( ch+ (len) ) == '=' ) f = 1;
         else if (*(ch+len)== '\0' ) break ;
         len ++;
     }
}
  
int main(){
     int i,j,n,mm;
     scanf ( "%d" , &n);
     for ( i = 0; i < n; i ++){
         scanf ( "%s" , ch);
         deal(ch,i);
     }
     scanf ( "%d" , &mm);
     for ( i = 0; i < mm; i++){
         scanf ( "%s" ,ch);
         b[ m[ch] ] = 1;
     }
  
     int f=1,num=0;
  
     while (f){
         f = 0;
         for ( i = 0; i < n; i ++){
             if (flag[i]) continue ;           ;           
             for ( j = 0, flag[i] = 1; j < vec1[i].size(); j ++)
                 if ( ! b[ vec1[i][j] ] )   flag[i] =0;
             if (flag[i]){
                 for ( j = 0; j < vec2[i].size(); j ++)
                     if ( ! b[ vec2[i][j] ] ) {
                         b[ vec2[i][j] ] = 1; 
                         ne[ vec2[i][j] ] = 1;
                         f = 1;
                         num++;
                     }
             }
         }
     }
     cout<<num<<endl;
     for ( map<string, int >::iterator i = m.begin(); i !=m.end(); i ++)
         if ( ne[ (*i).second ] ) cout<<(*i).first<<endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值