2018hdu个人排位赛:公孙玉龙

大致求的就是处理后的未被销毁的变量有多少

同值会被回收 ,被调用会被回收;

#include<bits/stdc++.h>
using namespace std;

map<string,string>mp1;
map<string,int>mp2;
int main()
{
    int T;
    cin>>T;
    while ( T-- )
    {
        int n;
        scanf("%d",&n);
        mp1.clear();
        mp2.clear();
        char a[110],b[110];
        for ( int i=1 ; i<=n ; i++ )
        {
            scanf ( "%s%s", a, b );
            if ( (b[0]>='0'&&b[0]<='9')||b[0]=='-' ) mp1[a] = b;
            else mp1[a] = mp1[b];
        }
        map<string,string>::iterator it;
        
        for ( it=mp1.begin() ; it!=mp1.end() ; it++ )
            mp2[it->second] = 1;
        printf ( "%d\n", mp2.size() );
    }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_41058467/article/details/81022408
今日推荐