used by istringstream UVA 12936

UVA 12936


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <map>
#include <string>
#include <string.h>
#include <set>
#include <queue>
#include <algorithm>
#include <sstream>

using namespace std;
typedef long long LL ;

char word[10008] ;

std::map<std::string , int> Id ;
int id ;

int getId(std::string s){
    if(Id.find(s) == Id.end()) return Id[s] = ++id ;
    return Id[s] ;
}

std::set<std::pair<int,int> >AtoB ;
bool can[108][108] ;

int gao(std::string s){
    int n = s.length() ;
    if((n % 2) != 0) return 0 ;
    if(s == "he") return 0 ;

    for(int i = 0 ; i < n ; i++){
        if(i&1){
           if(s[i] != 'e') return 0 ;
        }
        else{
           if(s[i] != 'h') return 0 ;
        }
    }

    return 1 ;
}

int main(){

    Id.clear() ;
    id = 0 ;
    AtoB.clear() ;
    memset(can , 0 , sizeof(can)) ;
    while(gets(word)){
        int n = strlen(word) ;
        for(int i = 0 ; i < n ; i++){
             if('A' <= word[i] && word[i] <= 'Z') word[i] = word[i] - 'A' + 'a' ;
             else if('a' <= word[i] && word[i] <= 'z'){}
             else word[i] = ' ' ;
        }
        std::string s = std::string(word) ;
        std::istringstream st(s)  ;
        std::string na ;
        int A , B ;
        int i = 0 ;
        while(st >> na){
            ++i ;
            if(i == 1) A = getId(na) ;
            else if(i == 2){
                B = getId(na) ;
                if(A > B) std::swap(A, B) ;
                AtoB.insert( std::make_pair(A , B) ) ;
                can[A][B] = 0 ;
            }
            else can[A][B] |= gao(na) ;
        }

    }

    double mu = AtoB.size() ;
    double zi = 0 ;
    for(std::set<std::pair<int ,int> >::iterator it = AtoB.begin() ; it != AtoB.end() ; it++){
        if(can[it->first][it->second]) zi += 1.0 ;
    }

    printf("%.0lf%%\n" , zi / mu  * 100.0) ;

    return 0 ;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值