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
  • 相关阅读:
    在web项目中使用配置文件
    javaFx教程 scene builder 加载第三方jar包
    getResource的两种用法
    tomcat部署工具
    withMisfireHandlingInstruction
    quartz教程三
    quartz教程二
    LocalDateTime与DateTimeFormatter
    quartz demo
    在小程序中点击后跳转到另一个小程序
  • 原文地址:https://www.cnblogs.com/codyanh/p/2282910.html
Copyright © 2011-2022 走看看