2013-10-25 最近碰到一道笔试题,是关于字符串翻转的.题目是:将一段英文翻转,但保留单词拼写,如给定字符串str="I am a student",返回为"student a am I".(为简单代码,设给定字符串由' '和字母组成). 对于这个题目我的思路是,先不管单词拼写,将str完全翻转得到str="tneduts a ma I",然后再对str中每个单词逐个翻转.代码实现如下 #include<stdio.h> #in
A string of '0's and '1's is monotone increasing if it consists of some number of '0's (possibly 0), followed by some number of '1's (also possibly 0.) We are given a string S of '0's and '1's, and we may flip any '0' to a '1' or a '1' to a '0'. Retu
Problem Description Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them. Input The input contains several test cases. The first line of the inpu
暴力法超时:思想:动态规划 public int minFlipsMonoIncrb(String S) { int result = S.length(); for (int i = 0; i < S.length(); i++) { char[] str1 = S.substring(0, i).toCharArray(); char[] str2 = S.substring(i + 1, S.length()).toCharArray(); int zero = 0; int one =