예제 #1
0
int romanToInt(char *s) {
  int length = strlen(s);
  if (length == 0 || strcmp(s, "") == 0) return 0;

  int ret = 0;
  for (int i=0; i < length; i++) {
    int current = map_to_int(s[i]);
    int left = map_to_int(s[i-1]);
    if (i > 0 && current > left) {
      ret += current - 2 * left;
    } else {
      ret += current;
    }
  }

  return ret;
}
예제 #2
0
파일: tagstats.cpp 프로젝트: Zverik/taginfo
int main(int argc, char *argv[]) {
    static struct option long_options[] = {
        {"debug",     no_argument, 0, 'd'},
        {"help",      no_argument, 0, 'H'},
#ifdef TAGSTATS_COUNT_TAG_COMBINATIONS
        {"tags-list", required_argument, 0, 'T'},
#endif // TAGSTATS_COUNT_TAG_COMBINATIONS
        {"top",       required_argument, 0, 't'},
        {"right",     required_argument, 0, 'r'},
        {"bottom",    required_argument, 0, 'b'},
        {"left",      required_argument, 0, 'l'},
        {"width",     required_argument, 0, 'w'},
        {"height",    required_argument, 0, 'h'},
        {0, 0, 0, 0}
    };

    bool debug = false;

    std::string tags_list;

    double top    =   90;
    double right  =  180;
    double bottom =  -90;
    double left   = -180;

    unsigned int width  = 360;
    unsigned int height = 180;

    while (true) {
        int c = getopt_long(argc, argv,
#ifdef TAGSTATS_COUNT_TAG_COMBINATIONS
        "dHT:t:r:b:l:w:h:",
#else
        "dHt:r:b:l:w:h:",
#endif // TAGSTATS_COUNT_TAG_COMBINATIONS
        long_options, 0);
        if (c == -1) {
            break;
        }

        switch (c) {
            case 'd':
                debug = true;
                break;
            case 'H':
                print_help();
                exit(0);
#ifdef TAGSTATS_COUNT_TAG_COMBINATIONS
            case 'T':
                tags_list = optarg;
                break;
#endif // TAGSTATS_COUNT_TAG_COMBINATIONS
            case 't':
                top = atof(optarg);
                break;
            case 'r':
                right = atof(optarg);
                break;
            case 'b':
                bottom = atof(optarg);
                break;
            case 'l':
                left = atof(optarg);
                break;
            case 'w':
                width = atoi(optarg);
                break;
            case 'h':
                height = atoi(optarg);
                break;
            default:
                exit(1);
        }
    }

    Osmium::init(debug);

    if (argc - optind != 2) {
        std::cerr << "Usage: " << argv[0] << " [OPTIONS] OSMFILE DATABASE" << std::endl;
        exit(1);
    }

    GeoDistribution::set_dimensions(width, height);
    Osmium::OSMFile infile(argv[optind]);
    Osmium::Sqlite::Database db(argv[optind+1]);
    MapToInt<rough_position_t> map_to_int(left, bottom, right, top, width, height);
    TagStatsHandler handler(db, tags_list, map_to_int);
    infile.read(handler);
}