20170330今日头条笔试题
2017-03-31 07:15
447 查看
只有四个编程题
1
2
3
4
参考答案 http://www.toutiao.com/i6403623293076636162/
1
2
3
#include <iostream> using namespace std; int main() { string s; cin>>s; int len = s.length(); int a[100]; int count = len; int level = 1; for(int i = 0; i < len; i++) { if(s[i] == '[') { a[i] = level; level++; } else { level--; a[i] = level; } } int max = a[0]; for(int i = 0; i < count; i++) { if(a[i] > max) { max = a[i]; } } for(int i = 0; i < count; i++) { a[i] = max - a[i] + 1; } for(int i = 0; i < count; i++) { cout<<a[i]<<endl; } for(int i = 0; i < count; i++) { if(a[i] == max) { cout<<"+"; for(int j = 0; j < max * 2 - 1; j++) { cout<<"-"; } cout<<"+"; cout<<endl; if(s[i] == '[' && s[i+1] == ']') { for(int j = 0; j < max-a[i]; j++) { cout<<" "; } cout<<"|"; for(int j = 0; j < a[i]*2 - 1; j++) { cout<<" "; } cout<<"|"<<endl; for(int j = 0; j < max-a[i]; j++) { cout<<" "; } cout<<"|"; for(int j = 0; j < a[i]*2 - 1; j++) { cout<<" "; } cout<<"|"<<endl; } } if(a[i] != max) { for(int j = 0; j < max-a[i]-1; j++) { cout<<" "; } cout<<"|+"; for(int j = 0; j < a[i] * 2 - 1; j++) { cout<<"-"; } cout<<"+|"; cout<<endl; if(s[i] == '[' && s[i+1] == ']') { for(int j = 0; j < max-a[i]; j++) { cout<<" "; } cout<<"|"; for(int j = 0; j < a[i]*2 - 1; j++) { cout<<" "; } cout<<"|"<<endl; for(int j = 0; j < max-a[i]; j++) { cout<<" "; } cout<<"|"; for(int j = 0; j < a[i]*2 - 1; j++) { cout<<" "; } cout<<"|"<<endl; } } } return 0; }
4
参考答案 http://www.toutiao.com/i6403623293076636162/
相关文章推荐
- 今日头条2017后端工程师实习生笔试题——最大映射
- 今日头条研发算法岗实习生笔试题解答篇_0324晚
- 今日头条秋招前端笔试附加题解题思路
- 今日头条2017校招笔试题
- Java编程题:今日头条笔试题
- 今日头条研发算法岗实习生笔试题题目篇_0324晚
- 今日头条笔试题
- 今日头条笔试8/23第二题
- 【今日头条笔试题】找一组坐标点的右边界点
- 今日头条2017后端工程师实习生笔试题
- 今日头条笔试题
- 【牛客网】马三来刷题之回文解码(今日头条2017年客户端实习在线笔试题)
- 今日头条笔试题
- [置顶] 今日头条2018春季校园招聘研发岗位笔试 题解 临时版
- 2018春招-今日头条笔试题-第一题(python)
- 今日头条2018春招笔试题js版本
- 2017.04.19:今日头条数据分析笔试01
- 今日头条笔试题:“最小数字*区间和”的最大值【单调栈】
- 2017-今日头条笔试题
- 今日头条 异或 笔试题