UVA10815 Andy's First Dictionary

2023-11-21 19:49
文章标签 first dictionary andy uva10815

本文主要是介绍UVA10815 Andy's First Dictionary,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

yiyi:大概意思是输入一个文本,然后把它按照字典序排好再输出。

Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him, as the number of words that he knows is, well, not quite enough. Instead of thinking up all the words himself, he has a briliant idea. From his bookshelf he would pick one of his favourite story books, from which he would copy out all the distinct words. By arranging the words in alphabetical order, he is done! Of course, it is a really time-consuming job, and this is where a computer program is helpful.

You are asked to write a program that lists all the different words in the input text. In this problem, a word is defined as a consecutive sequence of alphabets, in upper and/or lower case. Words with only one letter are also to be considered. Furthermore, your program must be CaSe InSeNsItIvE. For example, words like "Apple", "apple" or "APPLE" must be considered the same.

 

Input

The input file is a text with no more than 5000 lines. An input line has at most 200 characters. Input is terminated by EOF.

 

Output

Your output should give a list of different words that appears in the input text, one in a line. The words should all be in lower case, sorted in alphabetical order. You can be sure that he number of distinct words in the text does not exceed 5000.

 

Sample Input

Adventures in DisneylandTwo blondes were going to Disneyland when they came to a fork in the
road. The sign read: "Disneyland Left."So they went home.

 

Sample Output

a
adventures
blondes
came
disneyland
fork
going
home
in
left
read
road
sign
so
the
they
to
two
went
were
when

 答案:

#include <stdio.h>
#include <string.h>
#include <cctype>//#include <stdlib.h>  
//#include <algorithm> 
#include <iostream>
using namespace std;
int main () {char temp[200], ch;char word[5000][200];int flags = 0,k = 0, count = 0;while ((ch = getchar()) != EOF) {//判断是不是字母if (isalpha(ch)) {temp[k++] = tolower(ch);flags = 1;}else {if (flags) {//已读取完一个单词temp[k] = '\0';flags = 0;k = 0;int term, i = 0, j;while (i < count && (term = strcmp(temp, word[i])) > 0) //找出插入的位置i++;if (i == count) {strcpy(word[i], temp);count++;}else if (!term) //相等的字符串continue;else {for ( j = count; j > i; j--) {strcpy(word[j], word[j-1]);}strcpy(word[j], temp);count++;}}}}for (int a = 0; a < count; a++) {printf("%s\n", word[a]);}//system("pause");return 0;
}

这篇关于UVA10815 Andy's First Dictionary的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/404664

相关文章

广度优先搜索Breadth-First-Search

目录  1.问题 2.算法 3.代码 4.参考文献  1.问题         广度优先搜索,稍微学过算法的人都知道,网上也一大堆资料,这里就不做过多介绍了。直接看问题,还是从下图招到一条从城市Arad到Bucharest的路径。  该图是连通图,所以必然存在一条路径,只是如何找到最短路径。 2.算法 还是贴一个算法的伪代码吧: 1 procedu

[LeetCode] 524. Longest Word in Dictionary through Deleting

题:https://leetcode.com/problems/longest-word-in-dictionary-through-deleting/ 题目大意 对s删除某些元素,使得删除后的s 为 d中的某个元素。 思路 trie 首先将 建立tire,然后是用dfs搜索,遍历s。 boolean dfs(TrieNode node,String s,StringBuilder cu

LeetCode - 41. First Missing Positive

41. First Missing Positive  Problem's Link  ---------------------------------------------------------------------------- Mean:  给你一组整数,找出第一个空缺的正整数. 要求:时间O(n),空间O(n). analyse: 这题时间O(n)想了

如何使用 ef core 的 code first(fluent api)模式实现自定义类型转换器?

如何使用 ef core 的 code first 模式实现自定义类型转换器 前言 1. 项目结构2. 实现步骤2.1 定义转换器2.1.1 DateTime 转换器2.1.2 JsonDocument 转换器 2.2 创建实体类并配置数据结构类型2.3 定义 Utility 工具类2.4 配置 DbContext2.4.1 使用 EF Core 配置 DbContext 的两种实现方式2.

C++ std::multiset返回值 has no member named ‘first’

error: ‘std::multiset<>::iterator {aka struct std::_Rb_tree_const_iterator<>}’ has no member named ‘first’   multiset返回的直接是迭代器,所以没有first // INTEGER EXAMPLE // CPP program to illustrate // Implem

《Head First设计模式》之命令模式

命令模式就是将方法调用(Method invocation)封装起来。通过封装方法调用,我们可以把运算块包装成形,所以调用此运算的对象不需要关心事情是如何进行的,只要知道如何使用包装成形的方法来完成它就可以了。通过封装方法调用,可以用在以下场景:记录日志或者重复使用这些封装来实现撤销(undo)。     我对于命令模式的理解是:当我需要做一件事的时候,我只需要给出一个命令,这个命令中的

JavaScript - First step - Arrays

创建数组 任何类型的对象,都可以放入数组中。 var shopping = ['bread', 'milk', 'cheese', 'hummus', 'noodles'];shopping;// (5) ["bread", "milk", "cheese", "hummus", "noodles"]var sequence = [1, 1, 2, 3, 5, 8, 13];var ra

JavaScript - First step - Strings

var string = 'The revolution will not be televised.';var string = "The revolution will not be televised."; 转义字符 var bigmouth = 'I\'ve got no right to take my place...';bigmouth; 字符串连接 var one =

JavaScript - First step - Numbers and operators

Types of numbers Integers 整数Floating point numbers 单精度浮点数Doubles 双精度浮点数Binary 二进制Octal 八进制Hexadecimal 十六进制 Arithmetic operators 算术运算符 + 加法- 减法* 乘法/ 除法% 求余** 指数 (次方 5 ** 5 = 5 * 5 * 5 * 5 * 5) Oper

JavaScript - First step - Variables

Variable 变量是存放值的容器。使用 var 或者 let 关键字创建变量。 创建变量: let myName;let myAge; 此时变量容器是空的,没有值放在里面,若取得变量的值,返回值会是:undefine 初始化变量: myName = 'Chris';myAge = 37;let myDog = 'Rover'; var 和 let 的区别 为什么会有两个声明