1. 程式人生 > >20170330今日頭條筆試題

20170330今日頭條筆試題

只有四個程式設計題
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
這裡寫圖片描述
這裡寫圖片描述