0
点赞
收藏
分享

微信扫一扫

1179: 带参宏定义(函数专题)

归零者245号 2022-01-22 阅读 42
c++

1179: 带参宏定义(函数专题)

时间限制: 1 Sec  内存限制: 128 MB
提交: 41  解决: 73
[提交] [状态] [讨论版] [命题人:eilene]

题目描述

从键盘输入三个字符,用空格隔开,使用带参宏定义1中SWAP,将三个字符按从大到小的顺序排序输出。 
宏定义1:#define SWAP(a, b, t) { t=a; a=b; b=t; } 

请尝试,如果用宏定义2中的SWAP,主函数需要如何修改才能得到正确结果? 
宏定义2:#define SWAP(a, b, t) t=a; a=b; b=t; 

输入

输入三个字符,用空格隔开

输出

输出占一行,包含三个字符,用空格隔开

样例输入 Copy

w a q

样例输出 Copy

w q a
#include<bits/stdc++.h>
#define endl '\n'
#define SWAP(a, b, t) { t=a; a=b; b=t; }
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    char m,n,s,t;
    cin>>m>>n>>s;
    if(m<n)
        SWAP(m,n,t);
    if(m<s)
        SWAP(m,s,t);
    if(n<s)
        SWAP(n,s,t);
    cout<<m<<' '<<n<<' '<<s<<endl;
    return 0;
}

举报

相关推荐

0 条评论