微软笔试题-Constraint_Checker
来源:互联网 发布:dnfdll源码 编辑:程序博客网 时间:2024/04/28 10:44
#include <algorithm>#include <iostream>#include <map>#include <vector>#include <iterator>#include <string>#include <string.h>#define IMIN numeric_limits<int>::min()#define IMAX numeric_limits<int>::max()#define FR(i,n) for(int i=0;i<n;i++)#define CLC(x) memset(x,0,sizeof(x))#define FILL(x,c) memset(x,c,sizeof(x))#define viter vector<int>::const_iterator#define vcter vector<int>::const_iteratorusing namespace std;//字符串分割函数 vector<string> split(string s,string delim){ char *ss=const_cast<char *>(s.c_str()); const char *ddelim= delim.data(); char *token = strtok(ss,ddelim); vector<string> vstr; while(token!=NULL){ string stmp = token; vstr.push_back(stmp); token = strtok(NULL,ddelim); } return vstr;}//是否为大写字母 bool isCapital(char c){ if(c>='A'&&c<='Z')return true; else return false;}//处理一行字符串,将字母替换成具体的值 vector<string> getNewLine(const string &line,map<char,string> &mp){ int n = line.size(); vector<string> vs; string word; int lastisop=0; for(int i=0;i<n;++i){ if(line[i]=='<'){ if(word.size()==1&&isCapital(word[0])){ vs.push_back(mp[word[0]]); } else vs.push_back(word); word.clear(); if(line[i+1]=='='){ vs.push_back(string("<=")); i++; } else { vs.push_back(string("<")); } } else word.push_back(line[i]); } if(word.size()==1&&isCapital(word[0])){ vs.push_back(mp[word[0]]); } else vs.push_back(word); return vs;}//检查该行值逻辑是否成立 bool isSatisfied(vector<string> &vs){ int n=vs.size(); for(int i=1;i<n;i=i+2){ if(vs[i]=="<"){ if(atoi(vs[i-1].c_str())-atoi(vs[i+1].c_str())>=0)return false; } else if(vs[i]=="<="){ if(atoi(vs[i-1].c_str())-atoi(vs[i+1].c_str())>0)return false; } } return true;}//检查该组数逻辑是否成立 string isSucceed(vector<string> &cons,map<char,string> &mp){ int n = cons.size(); for(int i=0;i<n;++i){ vector<string> newl = getNewLine(cons[i],mp); //typedef ostream_iterator<string> OstreamStr; //copy(newl.begin(), newl.end(), OstreamStr(cout, " ")); //cout<<endl; if(isSatisfied(newl)==false)return string("No"); } return string("Yes");}//void Constraint_Checker(){ int m; string tmp; getline(cin,tmp); m = atoi(tmp.c_str()); vector<string> vs; map<char,int> mps; for(int i=0;i<m;++i){ tmp.clear(); getline(cin,tmp); for(int k=0;k<tmp.size();++k){ if(isCapital(tmp[k])){ if(!mps.count(tmp[k]))mps[tmp[k]]=1; } } vs.push_back(tmp); } //cout<<"over"<<endl; int n; getline(cin,tmp); n = atoi(tmp.c_str()); map<char,string> mp; string line; int wn = mps.size(); for(int x=0;x<n;++x){ mp.clear(); for(int y=0;y<wn;++y){ getline(cin,line); vector<string> row = split(line,string(" ")); if(!mp.count(row[0][0])) { mp[row[0][0]]=row[1]; } line.clear(); } string res = isSucceed(vs,mp); cout<<res<<endl; }}int main(){ Constraint_Checker(); return 0;}
0 0
- 微软笔试题-Constraint_Checker
- 微软笔试题-Constraint_Checker
- [转载] 微软笔试题
- 微软笔试题(zz)
- 微软笔试题3
- 微软笔试题4
- 微软笔试题一
- 微软笔试题
- 微软笔试题 汇总
- 2011微软笔试题
- 微软笔试题
- 微软笔试题
- 2011微软笔试题
- 微软笔试题
- 微软笔试题
- 微软笔试题:
- 微软PM笔试题
- 2013微软笔试题
- 二分查找不一定比顺序查找到的效率高
- 《Linux学习》之图形界面和字符界面的切换
- 文本框(JTextField)和文本域(JTextArea)的使用详解
- MVP、MVVM,MVC设计模式的实例分析
- 微软笔试题-Constraint_Checker
- 微软笔试题-Constraint_Checker
- HDU 1754 I Hate It(线段树单点更新区间最值查询)
- WEBRTC DataChannel SCTP
- OpenGeo Suite在Ubuntu14.04下安装
- oozie 介绍 ,安装 与应用
- 腾讯2017实习生编程题之构造回文
- node-sass 安装失败的解决措施
- python学习——urllib
- FOC矢量控制综述