多段階選抜(C++)



問題は以下URL
http://nabetani.sakura.ne.jp/hena/ord24eliseq/

ロジックは以下とほぼ同じですが、平方根、立方根を求めるロジックのみを変えています。
http://qiita.com/ryosy383/items/00f8a35eee0a1ba9b296


```cpp
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

#define MAX 10000

int main() {
    vector<int> sq;
    vector<int> cb;
    string input;

    for (int i = 1; i <= sqrt(MAX)+1; i++) {
        sq.push_back(i*i);
        cb.push_back(i*i*i);
    }

    while (1) {
        cin >> input;
		if (cin.fail())
			return 0;
        vector<int> ret, tmp;
        for (int i = 1; i <= MAX; i++) {
            ret.push_back(i);
        }
        for (int i = 0; i < input.length(); i++) {
            int count = 0, n,j,k;
            string s;
            copy(ret.begin(), ret.end(), back_inserter(tmp));


            switch (input[i]) {
            case 'S': {
                for (j = 0; j < ret.size(); j++) {
                    for (k = 0; k < sq.size(); k++) {
                        if (ret[j] == sq[k] && (count + 1) < tmp.size()) {
                            tmp[count + 1] = -1;
                        }
                    }
                    count++;

                }
                ret.clear();

                for (j = 0; j < tmp.size(); j++) {
                    if (tmp[j] != -1) {
                        ret.push_back(tmp[j]);
                    }
                }
                tmp.clear();
                break;
            }
            case 's': {
                for (j = 0; j < ret.size(); j++) {
                    for (k = 0; k < sq.size(); k++) {
                        if (ret[j] == sq[k] && (count - 1) >= 0) {
                            tmp[count - 1] = -1;
                        }
                    }
                    count++;

                }
                ret.clear();

                for (j = 0; j < tmp.size(); j++) {
                    if (tmp[j] != -1) {
                        ret.push_back(tmp[j]);
                    }
                }
                tmp.clear();
                break;
            }
            case 'C': {
                for (j = 0; j < ret.size(); j++) {
                    for (k = 0; k < cb.size(); k++) {
                        if (ret[j] == cb[k] && (count + 1) < tmp.size()) {
                            tmp[count + 1] = -1;
                        }
                    }
                    count++;

                }
                ret.clear();

                for (j = 0; j < tmp.size(); j++) {
                    if (tmp[j] != -1) {
                        ret.push_back(tmp[j]);
                    }
                }
                tmp.clear();
                break;
            }
            case 'c': {
                for (j = 0; j < ret.size(); j++) {
                    for (k = 0; k < cb.size(); k++) {
                        if (ret[j] == cb[k] && (count - 1) >= 0) {
                            tmp[count - 1] = -1;
                        }
                    }
                    count++;

                }
                ret.clear();

                for (j = 0; j < tmp.size(); j++) {
                    if (tmp[j] != -1) {
                        ret.push_back(tmp[j]);
                    }
                }

                tmp.clear();
                break;
            }
            case 'h': {
                ret.clear();
                for (j = 100; j < tmp.size(); j++) {
                    ret.push_back(tmp[j]);
                }
                tmp.clear();
                break;
            }
            default:
                ret.clear();
                s = input[i];
                n = atoi(s.c_str());
                for(j = 0; j < tmp.size(); j++) {
                    if (((j+1) % n) != 0) {
                        ret.push_back(tmp[j]);
                    }
                }
                tmp.clear();
                break;

            }
        }
        for (int x = 0; x < 10; x++) {
            printf("%d", ret[x]);
            if (x != 9) {
                printf(",");
            }
        }
        printf("\n");

    }
    return 0;

}
```