博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2015.09.13 网易游戏在线笔试(运营开发工程师)
阅读量:4620 次
发布时间:2019-06-09

本文共 2105 字,大约阅读时间需要 7 分钟。

题目一:IP测试

#include
#include
#include
#include
using namespace std; //对一个可能的数进行判断 int TESTIP(string s) { if(s.empty()||s.size()>3) return 0; if(s[0]=='0'&&s.length()>1) return 0; //将s转化为c风格字符串后转化为数字 int num=atoi(s.c_str()); if( num>=0 && num<=255 ) return 1; return 0; } //从start开始将s划分为num部分,结果存入result void IP(string &s,int start,int num,vector
&re,string &str) { if(num==0) { str.pop_back(); if(str.size()==s.size()+3) { re.push_back(str); } return; } int len=str.length(); int i; //划分出第一位可能的数 for(i=1; i<=3&&start+i<=(int)s.length(); i++) { string ss=s.substr(start,i); if(!TESTIP(ss)) continue; //若合适则添加到str后面,并继续划分剩下的数 str=str+ss+'.'; IP(s,start+i,num-1,re,str); str.erase(len,i+1); } }int main(){ string s; cin>>s; vector
result; string str; IP(s,0,4,result,str); sort(result.begin(),result.end()); for(unsigned int i=0; i
>s;}

题目二:统计输入字母

#include 
#include
#include
#include
#include
#include
//#include
using namespace std;//构造结构体,重载函数调用运算符为比较函数struct word { string s; int i; bool operator()(const word &a, const word &b) { if (a.i != b.i) return a.i > b.i; else return a.s < b.s; }};//或者新建比较函数bool compare(word a, word b){ if (a.i != b.i) return a.i > b.i; else return a.s < b.s;}int main(){ //将输入读取到str int n; cin>>n; string s, line; vector
str; while(n+1) { char line[100]; gets(line); istringstream stream(line); while (stream>>s) str.push_back(s); n--; } //建立结构体向量 vector
v; v.clear(); for (int i=0; i
s = str[i]; w->i = 1; v.push_back(*w); } } sort(v.begin(), v.end(), compare); for (int i=0; i

 

转载于:https://www.cnblogs.com/wangzhuazhua/p/4822485.html

你可能感兴趣的文章
每天CookBook之Python-036
查看>>
Django 之 cookie & session
查看>>
洛谷P2776 [SDOI2007]小组队列 链表 + 模拟
查看>>
ORA-39006错误原因及解决办法
查看>>
linux常用目录与作用
查看>>
PHP 后台定时循环刷新某个页面 屏蔽apache意外停止
查看>>
codeforces 622B B. The Time
查看>>
个人日报0628
查看>>
BeanDefinition的Resource定位——2
查看>>
学习记事
查看>>
java 子类重写父类的方法应注意的问题
查看>>
[LevelDB] LevelDB理论基础
查看>>
如果部署Excel 加载项?
查看>>
【codecombat】 试玩全攻略 第一关kithguard地牢
查看>>
【DP】 POJ 1191 棋盘分割 记忆化搜索
查看>>
自动化测试 Appium之Python运行环境搭建 Part2
查看>>
说说DBA职责和目标
查看>>
从头认识Spring-2.4 基于java的标准注解装配-@Inject-限定器@Named
查看>>
sql server 实现多表连接查询
查看>>
Python标准库:内置函数getattr(object, name[, default])
查看>>