栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 3914 Semantic Version

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 3914 Semantic Version

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <string>#include <cmath>#include <cstdlib>#include <vector>#include <queue>#include <set>#include <map>using namespace std;struct Version{vector<string> v_main;vector<string> v_other;void toString(){cout<<"show ...."<<endl;printf("v_main: %dn",v_main.size());for(int i=0;i<v_main.size();i++)cout<<v_main[i]<<",";cout<<endl;printf("v_other: %dn",v_other.size());for(int i=0;i<v_other.size();i++)cout<<v_other[i]<<",";cout<<endl;}}v1,v2;string line1,line2;Version getVersion(string line){int sz=line.size();string tmp="";bool flag=false;Version v;for(int i=0;i<sz;i++){if(line[i]=='.'||line[i]=='-'||i==sz-1){if(i==sz-1) tmp+=line[i];if(flag==false){v.v_main.push_back(tmp);}else if(flag==true){v.v_other.push_back(tmp);}if(line[i]=='-') flag=true;tmp="";continue;}tmp+=line[i];}return v;}int isBiger_num(string x,string y){int sz1=x.size();int sz2=y.size();if(sz1<sz2) return -1;if(sz2<sz1) return 1;bool equ=true;for(int i=0;i<sz1;i++){if(x[i]<y[i]) return -1;if(x[i]>y[i]) return 1;}return 0;}int isBiger_str(string x,string y){return strcmp(x.c_str(),y.c_str());}bool check_al(string str){for(int i=0,sz=str.size();i<sz;i++){if(str[i]>='0'&&str[i]<='9') continue;else return true;}return false;}int CMPVERSION(Version v1,Version v2){for(int i=0;i<3;i++){int cc=isBiger_num(v1.v_main[i],v2.v_main[i]);if(cc!=0) return cc;}int vo1=v1.v_other.size();int vo2=v2.v_other.size();if(vo1==0&&vo2==0) return 0;if(vo1==0&&vo2!=0) return 1;if(vo1!=0&&vo2==0) return -1;int msz=min(vo1,vo2);for(int i=0,sz=min(vo1,vo2);i<sz;i++){bool is_alpha1 = check_al(v1.v_other[i]);bool is_alpha2 = check_al(v2.v_other[i]);if(is_alpha1==true&&is_alpha2==true){int cc=isBiger_str(v1.v_other[i],v2.v_other[i]);if(cc!=0) return cc;}else if(is_alpha1==true&&is_alpha2==false){return 1;}else if(is_alpha1==false&&is_alpha2==true){return -1;}else if(is_alpha1==false&&is_alpha2==false){int cc=isBiger_num(v1.v_other[i],v2.v_other[i]);if(cc!=0) return cc;}}if(vo1>msz&&vo2==msz) return 1;if(vo2>msz&&vo1==msz) return -1;if(vo1==msz&&vo2==msz) return 0;}int main(){while(cin>>line1>>line2){v1=getVersion(line1);v2=getVersion(line2);int id=CMPVERSION(v1,v2);if(id==1||id==0) puts("I'm angry!");else puts("Wow! Such feature! Very smart! I'm excited!");}    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/379663.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号