• NYOJ 4 ASCII码排序(字符排序)283 对称排序(字符串排序)


    ASCII码排序

    时间限制:3000 ms  |           内存限制:65535 KB
    难度:2
     
    描述
    输入三个字符(可以重复)后,按各字符的ASCII码从小到大的顺序输出这三个字符。
     
    输入
    第一行输入一个数N,表示有N组测试数据。后面的N行输入多组数据,每组输入数据都是占一行,有三个字符组成,之间无空格。
    输出
    对于每组输入数据,输出一行,字符中间用一个空格分开。
    样例输入
    3
    qwe
    asd
    zxc
    样例输出
    e q w
    a d s
    c x z
     1  
     2 #include<stdio.h>
     3 #include<algorithm>
     4 using namespace std;
     5 char word[10];
     6 bool cmp( char a , char b )
     7 {
     8 return   b>a;
     9 }
    10 int main()
    11 {
    12     int i,n;
    13     scanf("%d",&n);
    14     while(n--){
    15         scanf("%s",word);
    16         sort(word,word+3,cmp);
    17         for(i=0;i<3;i++)
    18             printf("%c ",word[i]);
    19         printf("
    ");
    20    }
    21 return 0;
    22 }
    23         
    View Code

    对称排序

    题目:http://acm.nyist.net/JudgeOnline/problem.php?pid=283

    代码:

     1  
     2 #include<iostream>
     3 #include<string>
     4 #include<algorithm>
     5 using namespace std;
     6 bool cmp(string a,string b)
     7 {
     8     return a.length()<b.length();
     9 }
    10 int main(){
    11 string s[20];
    12 int i,j,n,t=0;
    13 while(cin>>n&&n){
    14     t++;
    15     for(i=0;i<n;i++)cin>>s[i];
    16     sort(s,s+n,cmp);
    17     cout<<"SET "<<t<<endl;
    18       for(i=0;i<n;i++)if(i%2==0)cout<<s[i]<<endl;
    19       for(i=n-1;i>=1;i--)if(i%2!=0)cout<<s[i]<<endl;
    20 }
    21 return 0;
    22 }
    23         
    View Code
     
  • 相关阅读:
    MFC的初始化过程和消息映射技术
    一些函数
    对话框相关
    windows新的数据类型
    VC++函数(win32_exe)
    Visual C++基础知识(win32exe)
    Keil C减小代码编译量大小的方法(gai)
    CM3存储器系统
    SPI总线
    SMBUS(IIC)总线
  • 原文地址:https://www.cnblogs.com/luoshuihanbing/p/3288782.html
Copyright © 2020-2023  润新知