字符串比较大小 并且去重
来源:互联网 发布:mac电脑磁盘在哪里 编辑:程序博客网 时间:2024/06/04 19:35
输入一行单词序列,相邻单词之间由1个或多个空格间隔,请按照字典序输出这些单词,要求重复的单词只输出一次。(区分大小写)
- 输入
- 一行单词序列,最少1个单词,最多100个单词,每个单词长度不超过50,单词之间用至少1个空格间隔。数据不含除字母、空格外的其他字符。
- 输出
- 按字典序输出这些单词,重复的单词只输出一次。
- 样例输入
She wants to go to Peking University to study Chinese
- 样例输出
ChinesePekingSheUniversitygostudytowants
//此题因为各种小错误 ,博主纠结了两个小时,最后找出错误的感觉真的很爽。
//二维数组传参比较重要
//Geeksun 2017.12.18
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void sort(char (*p)[60],int n);
int delete_str(char (*p)[60],int n);
int main()
{
int i = 0,count1 = 0,count2 = 0;
char word1[120][60],word2[121][60],temp[60];
while(scanf("%s",temp) != EOF)
{
if(temp[0] >= 65&&temp[0] <=90)
{
strcpy(word1[count1++],temp);
}
else if(temp[0] >= 97&&temp[0] <=122)
{
strcpy(word2[count2++],temp);
}
if(getchar() == '\n')
{
break;
}
}
sort(word1,count1);
sort(word2,count2);
count1 = delete_str(word1,count1);
count2 = delete_str(word2,count2);
for(i = 0;i < count1;i++)
{
printf("%s\n",word1[i]);
}
for(i = 0;i < count2;i++)
{
printf("%s\n",word2[i]);
}
return 0;
}
void sort(char (*p)[60],int n)
{
int i,j;
char temp[60];
for(i = 0;i < n - 1;i++)
{
for(j = 0;j < n - i - 1;j++)
{
if(strcmp(p[j],p[j + 1]) > 0)
{
strcpy(temp,p[j]);
strcpy(p[j],p[j + 1]);
strcpy(p[j + 1],temp);
}
}
}
}
int delete_str(char (*p)[60],int n)
{
int i,j;
for(i = 0;i < n - 1;i++)
{
if(strcmp(p[i],p[i + 1]) == 0)
{
for(j = i;j < n - 1;j++)
{
strcpy(p[j],p[j + 1]);
}
i--;
n--;
}
}
return n;
}
- 字符串比较大小 并且去重
- C++比较字符串的大小并且输出
- 去重并且合并联系人
- 字符串去重
- 字符串去重
- java 字符串去重
- js 字符串去重
- 字符串去重/C#
- 数字、字符串去重
- 字符串去重
- TreeSet去重字符串
- 字符串去重
- 字符串数组去重
- Java字符串去重
- 字符串数组去重
- 字符串去重
- js字符串去重
- 字符串去重 java
- Unable to configure Windows to Trust the Fiddler Root certificate.The LOG tab may contain more infor
- C语言实现RLE(游程编码)压缩算法(粘贴就能用)
- 生成器及注意事项
- CSS3过渡
- 程序员与公司政治
- 字符串比较大小 并且去重
- jackson json @JsonIgnore
- 【动态规划】之最长公共子序列长度(难度:1星)
- 最美英文情诗
- Nginx优化及部署LNMP
- LeetCode-1-Two Sum(C语言实现)
- Java Date和MySQL datetime数据类型转换
- MySQL TEXT数据类型的最大长度
- Servlet文件下载例子详解及response的contentType类型大全