Exercises 4-13

#include <stdio.h>
#define MAXLINE 1000
void reverse(char t[],char s[]);
int main(int argc, char *argv[])
{
    char s[]="4131025";
    char t[MAXLINE];
    reverse(t,s);
    printf("%s\n",t);
    return 0;
}
void reverse(char t[],char s[])
{
    static int i=0;
    static int j=0;
    if(s[i]!='\0')
    {
        i++;
        reverse(t,s);
    }
    t[j++]=s[--i];
    t[j]='\0';
}

分析:递归首先计算出字符串s的长度,然后递归逐层退出,把字符逐个复制给字符串t,达到倒序的效果。
Exercises for Programmers: 57 Challenges to Develop Your Coding Skills By 作者: Brian P. Hogan ISBN-10 书号: 1680501224 ISBN-13 书号: 9781680501223 Edition 版本: 1 出版日期: 2015-09-14 pages 页数: 118 When you write software, you need to be at the top of your game. Great programmers practice to keep their skills sharp. Get sharp and stay sharp with more than fifty practice exercises rooted in real-world scenarios. If you’re a new programmer, these challenges will help you learn what you need to break into the field, and if you’re a seasoned pro, you can use these exercises to learn that hot new language for your next gig. One of the best ways to learn a programming language is to use it to solve problems. That’s what this book is all about. Instead of questions rooted in theory, this book presents problems you’ll encounter in everyday software development. These problems are designed for people learning their first programming language, and they also provide a learning path for experienced developers to learn a new language quickly. Start with simple input and output programs. Do some currency conversion and figure out how many months it takes to pay off a credit card. Calculate blood alcohol content and determine if it’s safe to drive. Replace words in files and filter records, and use web services to display the weather, store data, and show how many people are in space right now. At the end you’ll tackle a few larger programs that will help you bring everything together. Each problem includes constraints and challenges to push you further, but it’s up to you to come up with the solutions. And next year, when you want to learn a new programming language or style of programming (perhaps OOP vs. functional), you can work through this book again, using new approaches to solve familiar problems. What You Need: You need access to a computer, a programming language reference, and the programming language you want to use.
### 在 Hive 中创建数据库、设置属性及创建不同类型的表 在 Hive 中,可以通过 SQL 语句完成数据库的创建、属性设置以及不同类型表的创建。以下是实现目标的具体方法。 #### 创建名为 `hive_exercises` 的数据库 使用以下命令可以创建一个名为 `hive_exercises` 的数据库,并将其日期属性设置为 `2023-12-13`: ```sql CREATE DATABASE IF NOT EXISTS hive_exercises WITH DBPROPERTIES ('date'='2023-12-13'); ``` 此命令通过 `WITH DBPROPERTIES` 子句设置了数据库的自定义属性[^1]。 #### 切换到 `hive_exercises` 数据库 在创建表之前,需要切换到目标数据库: ```sql USE hive_exercises; ``` #### 创建内部表 `goods_internal` 内部表(Managed Table)的数据存储在 Hive 的仓库目录中,与数据库的生命周期绑定。以下是创建内部表的 SQL 语句: ```sql CREATE TABLE IF NOT EXISTS goods_internal ( goods_id INT, goods_name STRING, price DOUBLE ); ``` 该表包含三个字段:`goods_id`(整数类型)、`goods_name`(字符串类型)和 `price`(双精度浮点数类型)[^2]。 #### 创建外部表 `goods_external` 外部表(External Table)的数据存储在指定的 HDFS 路径中,删除表时不会删除数据。以下是创建外部表的 SQL 语句: ```sql CREATE EXTERNAL TABLE IF NOT EXISTS goods_external ( goods_id INT, goods_name STRING, price DOUBLE ) LOCATION '/user/hive/warehouse/goods_external'; ``` 在此示例中,外部表的数据存储在 HDFS 路径 `/user/hive/warehouse/goods_external` 中[^3]。 #### 创建按 `goods_name` 分区的分区表 `goods_partition` 分区表允许根据特定列将数据分组存储,从而提高查询效率。以下是创建按 `goods_name` 分区的分区表的 SQL 语句: ```sql CREATE TABLE IF NOT EXISTS goods_partition ( goods_id INT, price DOUBLE ) PARTITIONED BY (goods_name STRING); ``` 此表将根据 `goods_name` 列进行分区存储,每个分区对应一个 `goods_name` 值[^4]。 #### 示例:向分区表插入数据 假设需要向 `goods_partition` 表中插入数据,可以使用以下命令: ```sql INSERT INTO goods_partition PARTITION (goods_name='ProductA') VALUES (1, 100.0); INSERT INTO goods_partition PARTITION (goods_name='ProductB') VALUES (2, 200.0); ``` ### 注意事项 - 确保 Hive 已正确配置并连接到 HDFS。 - 如果需要动态分区加载,可以在会话中启用动态分区功能: ```sql SET hive.exec.dynamic.partition=true; SET hive.exec.dynamic.partition.mode=nonstrict; ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值