# Re: 一著名软件公司的java笔试算法题！该如何解决(4)

www.MyException.Cn  网友分享于：2013-01-29  浏览：15次

321254
321425
321452
321524
321542
322145
322154
322415
322451
322514
322541
325124
325142
325214
325241
325412
325421
341225
341252
341522
342125
342152
342215
342251
342512
342521
345122
345212
345221
412325
412523
413225
413252
415223
415232
421325
421523
422315
422513
423125
423152
423215
423251
425123
425132
425213
425231
431225
431252
431522
432125
432152
432215
432251
432512
432521
451223
451232
451322
452123
452132
452213
452231
452312
452321
512234
512243
512324
512342
512423
512432
513224
513242
513422
521234
521243
521324
521342
521423
521432
522134
522143
522314
522341
522413
522431
523124
523142
523214
523241
523412
523421
541223
541232
541322
542123
542132
542213
542231
542312
542321
543122
543212
543221
Total count: 198
------解决方案--------------------

------解决方案--------------------

------解决方案--------------------

public class Test{
String s = "22 ";
String sc[] = { "22 "};
int ii = 0;
String sc1[] = new String[sc.length*(sc[0].length()+1)];;
for(int i=0;i <sc.length;i++){
String s = sc[i];
String sc2[] = getStrArray(s,ss);
for(int j=0;j <sc2.length;j++){
sc1[i*sc2.length+j] = sc2[j];
}
}
sc = sc1;
}
public String[] getStrArray(String s,String ss){
String newSc[] = new String[s.length()+1];
for(int i=0;i <=s.length();i++){
String s1 = s.substring(0,i);
String s2 = s.substring(i);
newSc[i] = s1+ss+s2;
}
return newSc;
}
public Test(){
for(int i=3;i <6;i++){
}
}
public static void main(String arg[]){
Test t = new Test();
int j = 0;
for(int i=0;i <t.sc.length;i++){
String s = t.sc[i];
if(!(s.indexOf( "35 ")> -1||s.indexOf( "53 ")> -1||s.indexOf( "4 ")==2)){
System.out.println( " 打印 S ： "+s);
j++;
}
}
System.out.println( " 符合条件的数共有： "+j+ "个 ");

}
}
------解决方案--------------------
#include "stdafx.h "
#include <vector>
#include <iostream>

using namespace std;

ostream& operator < < (ostream& os, vector <int> & v)
{
for(vector <int> ::iterator i = v.begin(); i != v.end(); ++i)
{
cout < < *(i) < < " ";
}

return os;
}

bool CanPrint(const vector <int> & position)
{
if(position[4] == 2)
{
return false;
}
else if(position[3] - position[5] == 1 || position[3] - position[5] == -1)