#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char code[1000][100];
bool solve(int p)
{
for(int i = 1; i < p; i++)
{
int len = min(strlen(code[i-1]), strlen(code[i]));
int j;
for(j = 0; j < len; j++)
{
if(code[i-1][j] != code[i][j])
break;
}
if(j == len)
return false;
}
return true;
}
int cmp(void const *va, void const *vb)
{
char *a = (char*)va;
char *b = (char*)vb;
return strcmp(a, b);
}
int main()
{
int d = 0;
while(scanf("%s", code[0]) != EOF)
{
int p = 1;
while(scanf("%s", code[p]) && code[p][0] != '9') { p++;}
qsort(code, p, sizeof(code[0]), cmp); /*这里sizeof内的要注意*/
if(solve(p))
printf("Set %d is immediately decodable\n", ++d);
else
printf("Set %d is not immediately decodable\n", ++d);
}
}

qsort介绍:https://www.runoob.com/cprogramming/c-function-qsort.html

思考:为什么要先排序再查找,不排序为何样例不通过?

Immediate Decodability UVA-644(qsort排序 + 模拟)的更多相关文章

  1. qsort排序算法

      七种qsort排序方法 <本文中排序都是采用的从小到大排序> 一.对int类型数组排序 int num[100]; Sample: int cmp ( const void *a ,  ...

  2. Milking Cows 挤牛奶 USACO 排序 模拟

    1005: 1.2.1 Milking Cows 挤牛奶 时间限制: 1 Sec  内存限制: 128 MB提交: 15  解决: 9[提交] [状态] [讨论版] [命题人:外部导入] 题目描述 1 ...

  3. UVa 644 Immediate Decodability

    吐槽下我的渣渣英语啊,即使叫谷歌翻译也没有看懂,最后还是自己读了好几遍题才读懂. 题目大意:题意很简单,就是给一些互不相同的由'0','1'组成的字符串,看看有没有一个字符串是否会成为另一个的开头的子 ...

  4. UVa 11039 Building designing (贪心+排序+模拟)

    题意:给定n个非0绝对值不相同的数,让他们排成一列,符号交替但绝对值递增,求最长的序列长度. 析:我个去简单啊,也就是个水题.首先先把他们的绝对值按递增的顺序排序,然后呢,挨着扫一遍,只有符号不同才计 ...

  5. UVa 1611 (排序 模拟) Crane

    假设数字1~i-1已经全部归位,则第i到第n个数为无序区间. 如果i在无序区间的前半段,那么直接将i换到第i个位置上. 否则先将i换到无序区间的前半段,再将i归位.这样每个数最多操作两次即可归位. # ...

  6. UVA 644 Immediate Decodability (字符处理)

    An encoding of a set of symbols is said to be immediately decodable if no code for one symbol is the ...

  7. sort和qsort排序

    qsort(数组名,数组长度,数组中每个元素大小,compare); compare函数的写法决定了排序是升序还是降序.需要#include<stdlib.h> 例如: int compa ...

  8. 用qsort排序

     冒泡,快排都是常见的排序方法,这里介绍用头文件里的qsort函数排序.只是自己要先一个cmp函数. #include<stdlib.h>//qsort的头文件 int a[100]= ...

  9. qsort 排序功能 总结

    qsort包括在<stdlib.h>头文件里.此函数依据你给的比較条件进行高速排序,通过指针移动实现排序. 排序之后的结果仍然放在原数组中.使用qsort函数必须自己写一个比較函数. 函数 ...

随机推荐

  1. sql 查找所有员工信息(俩表连接查询)

    题目描述 查找所有员工的last_name和first_name以及对应部门编号dept_no,也包括展示没有分配具体部门的员工CREATE TABLE `dept_emp` (`emp_no` in ...

  2. LeetCode 537. 复数乘法(Complex Number Multiplication)

    537. 复数乘法 537. Complex Number Multiplication 题目描述 Given two strings representing two complex numbers ...

  3. LeetCode 82. 删除排序链表中的重复元素 II(Remove Duplicates from Sorted List II)

    82. 删除排序链表中的重复元素 II 82. Remove Duplicates from Sorted List II 题目描述 给定一个排序链表,删除所有含有重复数字的节点,只保留原始链表中没有 ...

  4. 题解 P3957 【跳房子】

    对于这题有一个不用单调队列并且不是玄学设置区间最大值的做法 这题校内模拟考的时候打二分+枚举,结果写炸了,跑过来看题解发现为什么他们的区间最大值都是 $ 1005 $ ???特别懵,其实我的代码在dp ...

  5. 在Python中创建和使用类

    编程只是 if : 为了少写重复的代码,有了循环 for/while: 但碰到很长的重复代码,可能用一个循环难以实现,所以出现了面向对象的思想: 类:就是你的循环主体 实例:就是对你的循环的一次调用 ...

  6. Select与Epoll的区别

      相同点: 都是IO多路转接,都是一个线程能同一时间等待一堆描述符 不同点: 1.select接口使用不方便,每次调用完select都需要重新设置fd_set,因为输入输出未分离,返回的fd_set ...

  7. Create your first Java application

    参考链接 -[IntelliJ IDEA] https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-appli ...

  8. Java 二叉搜索树 实现和学习

    /** * <html> * <body> * <P> Copyright 1994 JsonInternational</p> * <p> ...

  9. JNA的应用

    一.了解JNA之前,我们先了解一下JNA的前身JNI(Java Native Interface):通过使用 Java本地接口书写程序,可以确保代码在不同的平台上方便移植. [1]  从Java1.1 ...

  10. NEST routing timeout scroll

    /// <summary> /// PUT /employee/employee/9e5e50da-7740-488e-bee2-b24951435691?routing=test_rou ...