• 算法oj_q3_奇偶分离


    /*奇偶数分离
    时间限制:3000 ms  |  内存限制:65535 KB
    难度:1
    描述
    有一个整型偶数n(2<= n <=10000),你要做的是:先把1到n中的所有奇数从小到大输出,再把所有的偶数从小到大输出。
    输入
    第一行有一个整数i(2<=i<30)表示有 i 组测试数据;
    每组有一个整型偶数n。
    输出
    第一行输出所有的奇数
    第二行输出所有的偶数
    样例输入
    2
    10
    14
    样例输出
    1 3 5 7 9 
    2 4 6 8 10 
    
    1 3 5 7 9 11 13 
    2 4 6 8 10 12 14 
    
    来源
    [苗栋栋]原创
    上传者
    苗栋栋
    */
    #include<iostream>
    using namespace std;
    
    int main(){
        int kase = 0;
        cin >> kase;
        for (int i = 0; i < kase; i++)
        {
            int n = 0;
            bool isFirst = true;
            cin >> n;
            for (int j = 1; j <= n; j+=2)
            {
                if (!isFirst)
                    cout << " ";
                isFirst = false;
                cout << j;
            }
            cout << endl;
            isFirst = true;
            for (int k = 2; k <= n ; k+=2)
            {
                if (!isFirst)
                    cout << " ";
                isFirst = false;
                cout << k;
            }
            cout << endl;
            cout << endl;
        }
        return 0;
    }

    //如果您发现博主算法哪里有问题,或者您有更好的算法,欢迎留下您的评论

  • 相关阅读:
    ==与is区别
    词典操作
    前端工具---取色截图测量
    css零碎合集
    基于bootstrap的在线布局工具
    js常用功能工具库--Underscore.js
    前端资源荟萃
    在线绘图工具---processon
    表单form浅谈
    前端工具----iconfont
  • 原文地址:https://www.cnblogs.com/ncgds/p/7497179.html
Copyright © 2020-2023  润新知