2414: C语言习题 字符串排序

时间限制: 1 Sec  内存限制: 128 MB

提交: 656  解决: 305

题目描述

输入n个字符串,将它们按字母由小到大的顺序排列并输出。编写三个函数实现,input 用于输出n个字符串,sortstr用于排序n个字符串,output 用于输出n个字符串。

输入

第一行 n
第二行到第n+1行,每行一个字符串

输出

排序后的字符串

样例输入

3
YTU
ACM
COM

样例输出

ACM
COM
YTU

提示

主函数已给定如下,提交时不需要包含下述主函数

/* C++代码 */
int main()
{
   string str[10];
   int n;
   cin>>n;
   input( str, n);
   sortstr( str, n);
   output( str, n);
   return 0;
}

迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
void sort(char *[],int n);
int i,n;
char str[10][80];
char *p[10];
scanf("%d",&n);
for (i=0; i<n; i++)
scanf("%s",str[i]);
for (i=0; i<n; i++)
p[i]=str[i];
sort(p,n);
for (i=0; i<n; i++)
printf("%s\n",p[i]);
return 0;
}
void sort(char *p[],int n)
{
int i,j;
char s[999];
for(i=0; i<n-1; i++)
for(j=0; j<n-i-1; j++)
if(strcmp(p[j],p[j+1])>=0)
{
strcpy(s,p[j]);
strcpy(p[j],p[j+1]);
strcpy(p[j+1],s);
}
}

YTU 2414: C语言习题 字符串排序的更多相关文章

  1. YTU 2426: C语言习题 字符串排序

    2426: C语言习题 字符串排序 时间限制: 1 Sec  内存限制: 128 MB 提交: 262  解决: 164 题目描述 用指向指针的指针的方法对5个字符串排序并输出.要求将排序单独写成一个 ...

  2. YTU 2424: C语言习题 字符串比较

    2424: C语言习题 字符串比较 时间限制: 1 Sec  内存限制: 128 MB 提交: 1042  解决: 613 题目描述 写一函数,实现两个字符串的比较.即自己写一个strcmp函数,函数 ...

  3. YTU 2417: C语言习题 字符串长度

    2417: C语言习题 字符串长度 时间限制: 1 Sec  内存限制: 128 MB 提交: 758  解决: 548 题目描述 写一函数,求一个字符串的长度.在main函数中输入字符串,并输出其长 ...

  4. YTU 2427: C语言习题 整数排序

    2427: C语言习题 整数排序 时间限制: 1 Sec  内存限制: 128 MB 提交: 391  解决: 282 题目描述 用指向指针的指针的方法对n个整数排序并输出.要求将排序单独写成一个函数 ...

  5. C 语言实例 - 字符串排序

    C 语言实例 - 字符串排序 C 语言实例 C 语言实例 按字典顺序排序. 实例 #include<stdio.h> #include <string.h> int main( ...

  6. YTU 2420: C语言习题 不等长字符串排序

    2420: C语言习题 不等长字符串排序 时间限制: 1 Sec  内存限制: 128 MB 提交: 460  解决: 239 题目描述 在主函数中输入n(n<=10)个不等长的字符串.用另一函 ...

  7. YTU 2419: C语言习题 等长字符串排序

    2419: C语言习题 等长字符串排序 时间限制: 1 Sec  内存限制: 128 MB 提交: 650  解决: 249 题目描述 在主函数中输入n(n<=10)个等长的字符串.用另一函数对 ...

  8. 浅谈iOS开发中多语言的字符串排序

    一.前言 在iOS开发中,一个经常的场景是利用tableview展示一组数据,以很多首歌曲为例子.为了便于查找,一般会把这些歌曲按照一定的顺序排列,还会加上索引条以便于快速定位. 由于歌曲名可能有数字 ...

  9. YTU 2974: C语言习题5.26--文件操作3

    2974: C语言习题5.26--文件操作3 时间限制: 1 Sec  内存限制: 128 MB 提交: 213  解决: 92 题目描述 文本文件score.dic 中存储了n名学生的信息(班级编号 ...

随机推荐

  1. ubuntu修改apt-get源为国内镜像源

    1.原文件备份   sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak   2.编辑源列表文件   sudo vim /etc/apt/so ...

  2. 【Codeforces 1083A】The Fair Nut and the Best Path

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 我们最后要的是一条最长的路径. 这条路径的权值和是所有点的权值和-所有边的权值和且这个值最大. 显然如果我们在某一条边上的累计的权值和< ...

  3. java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver

    今天这个问题排查了好大一会,开始网上有人这么说: https://www.cnblogs.com/rookiebob/p/3749396.html 但是仍未能解决我的问题, 最后发现是只在外层的pom ...

  4. Git x SVN 当前工作流程

    git-svn 当前工作流程 @ixenos 2018-12-27 21:37:47 前言:用惯了git,再用svn简直反人类,所以……还是用git-svn过渡一下 (由于远程还没有dev,直接坑爹地 ...

  5. PAT (Advanced Level) 1035. Password (20)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

  6. CodeForces 599B Spongebob and Joke

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

  7. BZOJ 1798:

    6:       LAZY 线段树有乘法的更新    #include <cstdio> #include <cstring> #include <algorithm&g ...

  8. JAVA实现选择排序,插入排序,冒泡排序,以及两个有序数组的合并

    一直到大四才开始写自己的第一篇博客,说来实在有点羞愧.今天写了关于排序的算法题,有插入排序,冒泡排序,选择排序,以下贴上用JAVA实现的代码: public class test5 { public ...

  9. Maven使用tomcat7-maven-plugin插件run时出现错误: A child container failed during start java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component

    错误如下: A child container failed during startjava.util.concurrent.ExecutionException: org.apache.catal ...

  10. Desert King (poj 2728 最优比率生成树 0-1分数规划)

    Language: Default Desert King Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 22113   A ...