codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include <cstdio> #include <cstdlib> #include <cmath> #include <climits> #include <cfloat> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include <functional> #include <sstream> #include <complex> #include <stack> #include <queue> #include <numeric> using namespace std; static const double EPS = 1e-9; int ROUND(double x) { return (int)(x+0.5); } bool ISINT(double x) { return fabs(ROUND(x)-x)<EPS; } bool ISEQUAL(double x,double y) { return fabs(x-y)<EPS; } #define PI (3.14159265358979323846) template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; } double SQSUM(double x,double y) { return x*x+y*y; } #define SZ(a) ((int)a.size()) class OperationsArrangement { public: string arrange(string sequence) { string result; //----- 0あり ----- if(sequence.find("0")!=string::npos) { for(int i=0;i<SZ(sequence);i++) { result += string(1,sequence[i]); if(i<SZ(sequence)-1) { result += "*"; } } return result; } //----- 0なし ----- string seq2 = sequence; // いったん1を除去 string::iterator end_it = remove( seq2.begin(), seq2.end(), '1' ); seq2.erase( end_it, seq2.end() ); // 2が2回連続したところだけ*,あとは+ int cont2 = 0; // 2の連続回数 for(int i=0;i<SZ(seq2);i++) { if(seq2[i]=='2') { cont2++; } else { cont2 = 0; } if(i>0) { if(cont2==2) { result += "*"; cont2 = 0; // 2*2+2*2のようにしたい。ここがないと、2*2+2+2となってしまう。 } else { result += "+"; } } result += string(1,seq2[i]); } // 1を戻す bool beginning1 = true; // しょっぱなからの1が続いていればtrue for(int i=0;i<SZ(sequence);i++) { if(sequence[i]=='1') { if(beginning1) { if(i!=SZ(sequence)-1) { result.insert(i*2,"1*"); } else { // 特例:全部1のとき result.insert(i*2,"1"); } } else { result.insert(i*2-1,"*1"); } } else { beginning1 = false; } } return result; } }; // Powered by FileEdit // Powered by TZTester 1.01 [25-Feb-2003] // Powered by CodeProcessor
Private
[
?
]
Run code
Submit