zoukankan      html  css  js  c++  java
  • 经典函数看待问题。。

    熟用经典函数可让问题得到简化。。特别是正式需要用得时候能省下很多事情。

    比如下面的例题:在执行栈和队列的操作时,,我们需要通过不同的方式,

    好比链表重新建立往往浪费了时间——无效。。。

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <math.h>
    #include <queue>
    using namespace std;
    queue<int> q;
    int main()
    {
        int n,t;
        scanf( "%d" , &n );
        for( int i = 0 ; i < n ; i++ )
        q.push(i+1);
        while( !q.empty())
        {
               
            t=q.front();
            q.pop();
            q.push(q.front());
            q.pop();
         
        }
        printf("%d",t);
         puts("");
        //system("pause");
        return 0;
    }
    本以为这样可以解决杀人环的问题,但是Compile Error将中间改成如下:
     
     
    for( int i = 0 ; i < n ; i++ )
        q.push(i+1);
        while( !q.empty())
        {
               
            printf( "%d" , (q.front())'
            q.pop();
            q.push(q.front());
            q.pop();
         
        }
         样例输入:3
        
         样例输出:1 3 2
        
         样例输入:7
        
         样例输出:1 3 5 7 4 2 6
  • 相关阅读:
    CodeForces 734F Anton and School
    CodeForces 733F Drivers Dissatisfaction
    CodeForces 733C Epidemic in Monstropolis
    ZOJ 3498 Javabeans
    ZOJ 3497 Mistwald
    ZOJ 3495 Lego Bricks
    CodeForces 732F Tourist Reform
    CodeForces 732E Sockets
    CodeForces 731E Funny Game
    CodeForces 731D 80-th Level Archeology
  • 原文地址:https://www.cnblogs.com/codyanh/p/2282910.html
Copyright © 2011-2022 走看看