I didn't understand at first , what Home key , what End key , I thought it was equivalent to brackets ,[] What's in it is printed out first . Later, baidu made a decision . I'm sorry ...

The question : Given a string , The interior contains '[' and ']' Cursor transfer command ,'[' Represents the cursor moving to the head of the article ,']' Represents the cursor moving to the end of the article , What is the string sequence that will eventually be displayed on the screen

Ideas : Just simulate it directly , However, because it is possible to move to the beginning and end of the string , So I drove 3 individual char Array .

str1 Storage due to '[' The reason for printing at the beginning of the character ,str3 Storage due to ']' The reason for printing at the end of the character ,str2 The storage did not meet at the beginning '[' or ']' Previous characters .

stay A This question is 15 Inside the individual , I wrote the fastest ,82MS, Just a little smug .

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <stack> using namespace std;
stack<char> s;
char str[]; char ans1[];
char ans2[];
char ans3[];
int main() {
while(scanf("%s",str)!=EOF) {
int len=strlen(str);
//preidx Express ans1 The location of the last index in ( It's moving from the back to the front )
//idx Namely ans2 The location of the index in
//aftidx Refer to ans3 The location of the index in
int preidx=,idx=,aftidx=;
for(int i=; i<len; i++) {
char ch=str[i];
if(ch=='[') {
//l Record '[' The position of the first character after
int l=++i;
while(i<len && str[i]!='[' && str[i]!=']') {
//ans=str.charAt(i)+ans;
i++;
}
// Last i-1 It's a record of what happened next '[' or ']' The previous position of
for(int j=i-; j>=l; j--) {
ans1[preidx]=str[j];
preidx--;
}
i--;
} else if(ch==']') {
int l=++i;
while(i<len && str[i]!='['&& str[i]!=']') {
i++;
}
for(int j=l; j<i; j++) {
ans3[aftidx]=str[j];
aftidx++;
}
i--;
} else {
ans2[idx]=str[i];
idx++;
}
}
for(int i=preidx+; i<=; i++)
printf("%c",ans1[i]);
for(int i=; i<idx; i++)
printf("%c",ans2[i]);
for(int i=; i<aftidx; i++)
printf("%c",ans3[i]);
printf("\n");
}
return ;
}

The second one of summer training competition UVA 11988 Broken Keyboard (a.k.a. Beiju Text)( string manipulation ) More articles about

  1. The second one of summer training competition UVA 10982 Troublemakers

    The question : Put the points in two sets , The edges of the same set are preserved , The edges of different sets are deleted , Make the edges at least halve .  Output any scheme . If not , Output Impossible  Ideas : If two people are a pair of troublemakers , be two[i][j]=t ...

  2. UVA 11988 Broken Keyboard (a.k.a. Beiju Text)( Linked list )

    Title code :UVA 11988 Topic link :https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&pa ...

  3. The first one of the summer training competition UVA 1737 Mnemonics and Palindromes 3

    The question : Seeking the cause a,b,c The length of the three letters is n String , Its arbitrary continuous length is greater than or equal to 2 None of the substrings of are palindromes , How many kinds of strings are there ? And dictionary order output If the total length of all kinds of strings is greater than 100000 Characters , It outputs TO ...

  4. Linked list UVA 11988 Broken Keyboard (a.k.a. Beiju Text)

    Subject portal The question : Training guide P244 analysis : Linked list simulation , Maintenance of linked list head and tail The pointer #include <bits/stdc++.h> using namespace std; const ...

  5. UVa 11988 Broken Keyboard (a.k.a. Beiju Text)

    It's too much trouble to copy the title , A link http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18693 Direct simulation cursor operation time complexity is high , So with the chain ...

  6. UVa 11988 - Broken Keyboard (a.k.a. Beiju Text) Answer key

    Liu Rujia's topic , Tragic text -_-||| Use here vector<string> The container is inverted to record data , And then output from the back . The difficulty is not knowing where to start outputting this kind of document , So using a container for dynamically managing memory is better than ...

  7. UVa 11988 Broken Keyboard (a.k.a. Beiju Text)( Linked list )

    You're typing a long text with a broken keyboard. Well it's not so badly broken. The only problem wi ...

  8. UVA 11988 Broken Keyboard (a.k.a. Beiju Text) ( Linked list , simulation )

    Use list Just simulate it , If you are familiar with list, So this question is really lost every minute ... list It's a two-way circular list , Insert and delete operations are very fast , The disadvantage is that you can't read by subscript randomly like an array . Now, yes wiki The correlation function described above :http ...

  9. UVA——11988 Broken Keyboard (a.k.a. Beiju Text)

    11988 Broken Keyboard (a.k.a. Beiju Text)You’re typing a long text with a broken keyboard. Well it’s ...

Random recommendation

  1. Spring Configuration file details

      from : http://book.51cto.com/art/201004/193743.htm Here is a detailed explanation of spring2.5 Implementation principle of , It feels very useful spring Configuration files are used to guide Sp ...

  2. Libjingle Library profile

    Link to the original text Many voice chat tools in China are based on TURN Realized by , Include YY.AK wait , This method requires high performance of the server , And as the number of users increases , The pressure on the server will also increase , The voice quality of users will also be greatly affected . And base ...

  3. 【 probability 】BZOJ 3450:Tyvj1952 Easy

    Description One day WJMZBMR Fight osu~~~ But he's too weak , In some places, it's all luck :( Let's simplify the rules of the game Yes n One click to do , Success is o, Failure is x, The score is based on comb Calculated , even ...

  4. JavaScript Advanced programming ( The third edition ) Learning notes 1~5 Chapter

    The first 2 Chapter , stay html Use in JavaScript Html Introduce the outside js Script <script type="text/javascript" src="test.js&qu ...

  5. Neral Preface to

    Hello everyone , I am a Neral, I'm going to write a js library . Before you start writing , I've always been in a very nervous state , Because what I write code for is a feeling , It's the pleasure of seeing the code you've written, and then there are countless coding branches in your brain , however , If for a long time ...

  6. javaweb Remove one of the get Parameters of the way , And return to the path

    String requestURL = request.getRequestURL() + ""; // String queryString = request.getQuery ...

  7. [CLR via C#]1.1 Compile source code into managed code

    original text :[CLR via C#]1.1 Compile source code into managed code 1.  Common language runtime (Common Language Runtime,CLR) It's a language that can be used by many programming languages " Runtime ". ...

  8. iOS Open source library And AFNetWorking 2.x

    1. Basic knowledge of network request 2. Get/Post Use of request 3. file ( picture ) Upload 4. Breakpoint download 5. Other usage details 6. Well designed places

  9. fastjson from 1.1.41 Upgrade to 1.2.28 The pit of

    Recently because fastjson Security vulnerabilities , upgrade jar Packet time , Stepped on some pits . The new version FastJsonHttpMessageConverter initialization , default setting MediaType by */* background : Use Spring Re ...

  10. Data structure Treap

    1. summary Same as splay tree equally ,treap It's also a balanced binary tree , however Treap An extra piece of data will be recorded , Priority .Treap While constructing binary search tree with key code , It also satisfies the nature of the heap by priority . thus ,Treap ...