当前位置: 首页>>代码示例>>C++>>正文


C++ map::swap方法代码示例

本文整理汇总了C++中map::swap方法的典型用法代码示例。如果您正苦于以下问题:C++ map::swap方法的具体用法?C++ map::swap怎么用?C++ map::swap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在map的用法示例。


在下文中一共展示了map::swap方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main() {
  int n, q, x;
  string vs, vt;

#ifndef __WATASHI__
  freopen("shuffle.in", "r", stdin);
  freopen("shuffle.out", "w", stdout);
#endif
  scanf("%d%d%d", &n, &q, &p);
  vs.resize(n);
  vt.resize(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x);
    vs[i] = (char)(x - 1);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x);
    vt[i] = (char)(x - 1);
  }
  for (int i = 0; i < p; ++i) {
    scanf("%d%d", &l[i], &m[i]);
    l[i] = n - l[i];
    m[i] = l[i] - m[i];
  }

  // forward (bfs)
  s.clear();
  s[vs] = "";
  for (int i = 0; i < q / 2; ++i) {
    map<string, string> tmp;
    for (const auto& j: s) {
      for (int k = 0; k < p; ++k) {
        string v = j.first;
        rotate(v.begin(), v.begin() + m[k], v.begin() + l[k]);
        tmp[v] = j.second + (char)('1' + k);
      }
    }
    s.swap(tmp);
  }
  fprintf(stderr, "s.size() = %d\n", (int)s.size());

  // backward (dfs)
  for (int i = 0; i < p; ++i) {
    m[i] = l[i] - m[i];
  }
  try {
    dfs((q + 1) / 2, vt);
    puts("Impossible");
  } catch (string ans) {
    for (int i = 0; i < q; ++i) {
      printf("%c%c", ans[i], i == q - 1 ? '\n' : ' ');
    }
  }

  return 0;
}
开发者ID:Crmiv,项目名称:AlgoSolution,代码行数:56,代码来源:J.cpp

示例2: swap

void swap(map<Key, Value, Compare>& _x, map<Key, Value, Compare>& _y) { _x.swap(_y); }
开发者ID:zoid,项目名称:ztl,代码行数:1,代码来源:map.hpp

示例3: main


//.........这里部分代码省略.........
    }
    catch ( const FileIOException &fioex ) {
        cerr << "I/O error while reading file." << "\n";
        return ( EXIT_FAILURE );
    }
    catch ( const ParseException &pex ) {
        cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine()
             << " - " << pex.getError() << "\n";
        return(EXIT_FAILURE);
    }

    string port;
    string pull_socket_count;
    string pull_socket;
    string push_socket_samples;
    string push_socket;
    string min_query_length_cfg;
    string max_query_length_cfg;
    string max_query_length_count_threshold_cfg;
    string max_match_reads_cfg;
    string workers;

    try {
        const Setting& rs = cfg.getRoot();
        if ( rs.exists("max_read_length") ) {
            MAX_READ_LENGTH = atoi(cfg.lookup("max_read_length").c_str());
        }
        if ( rs.exists("min_read_length") ) {
            MIN_READ_LENGTH = atoi(cfg.lookup("min_read_length").c_str());
        }

        port = cfg.lookup("port").c_str();
        pull_socket_count = cfg.lookup("pull_socket_count").c_str();
        pull_socket = cfg.lookup("pull_socket").c_str();
        push_socket_samples = cfg.lookup("push_socket_samples").c_str();
        push_socket = cfg.lookup("push_socket").c_str();
        min_query_length_cfg = cfg.lookup("min_query_length").c_str();
        max_query_length_cfg = cfg.lookup("max_query_length").c_str();
        max_query_length_count_threshold_cfg = cfg.lookup("max_query_length_count_threshold").c_str();
        max_match_reads_cfg = cfg.lookup("max_match_reads").c_str();
        workers = cfg.lookup("workers").c_str();
    }
    catch ( const SettingNotFoundException &nfex )
    {
        cerr << "No 'name' setting in configuration file." << "\n";
        return(EXIT_FAILURE);
    }

    workers_count = atoi(workers.c_str());
    min_query_length = atoi(min_query_length_cfg.c_str());
    max_query_length = atoi(max_query_length_cfg.c_str());
    max_query_length_count_threshold = atoi(max_query_length_count_threshold_cfg.c_str());
    max_match_reads = atoi(max_match_reads_cfg.c_str());

    try {
        receiver_count.bind(pull_socket_count.c_str());
        receiver.bind(pull_socket.c_str());
        int hwm = 0;
        sender_samples.setsockopt(ZMQ_SNDHWM, &hwm, sizeof(hwm));
        sender_samples.setsockopt(ZMQ_RCVHWM, &hwm, sizeof(hwm));
        sender_samples.bind(push_socket_samples.c_str());
        sender.bind(push_socket.c_str());
    }
    catch ( const zmq::error_t& er ) {
        cerr << "error in binding with nubmer " << er.num() << "\n";
    }

    std::this_thread::sleep_for(std::chrono::milliseconds( 1 * 6 * 1000));

    pthread_t worker;
    pthread_create(&worker, NULL, worker_routine, NULL);

    pthread_t counter;
    pthread_create(&counter, NULL, counter_routine, NULL);

    struct mg_server *server;

    // Create and configure the server
    server = mg_create_server(NULL, request_handler);
    mg_set_option(server, "listening_port", port.c_str());

    // Serve request. Hit Ctrl-C to terminate the program
    cerr << "start listening on port " << port << "\n";
    for (;;) {
        completed_requests.clear();
        {
            lock_guard<mutex> lg(mtx);
            completed_requests.swap(completed_responses);
        }
        mg_poll_server(server, 10);
    }

    // Cleanup, and free server instance
    mg_destroy_server(&server);

    // Optional:  Delete all global objects allocated by libprotobuf.
    google::protobuf::ShutdownProtobufLibrary();

    return 0;
}
开发者ID:wtsi-svi,项目名称:ReadServer,代码行数:101,代码来源:server.cpp


注:本文中的map::swap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。