转跳点:  

这道题我记得谷歌 2012 年校招,百度201年校招好向出过。所以我想,了一个及其奇葩的代码。(模拟了栈的理念)代码有些奇葩。

  我利用了scanf函数遇到“ ”停止的特性模拟了栈的push,用printf遇到'\0'结束模拟了pop,设定了一个栈顶指针指向当前栈顶元素。因为栈的先进后出的特性,加上%s输出的特性,就完成了对单词顺序的反转

代码实现如下:

 1 #include <stdio.h>
2 #include <stdlib.h>
3 #define MAXSIZE 100
4
5 typedef struct
6 {
7 char Str[MAXSIZE / 4];
8 } Stack;
9
10 int main()
11 {
12 int bottom = -1;
13 Stack str[MAXSIZE];
14
15 while (scanf("%s", &str[++bottom]) != EOF && str[bottom].Str[0] != '#')
16 ;
17 while (bottom != 0)
18 printf("%s%s", str[bottom].Str, 0 == --bottom ? "" : " ");
19
20 return 0;
21 }

结构体数组

  这个是用二维数组实现的:

 1 #include <stdio.h>
2 #include <stdlib.h>
3 #define MAXSIZE 100
4
5 int main()
6 {
7 int bottom = -1;
8 char str[MAXSIZE][MAXSIZE / 4];
9
10 while (scanf("%s", &str[++bottom]) != EOF && str[bottom][0] != '\n')
11 ;
12
13 while (bottom != 0)
14 printf("%s%s", str[bottom], 0 == --bottom ? "" : " ");
15
16 return 0;
17 }

二维数组

   PAT不易,诸君共勉!

P 1008 说反话的更多相关文章

  1. HDOJ 1008. Elevator 简单模拟水题

    Elevator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  2. poj 1008:Maya Calendar(模拟题,玛雅日历转换)

    Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64795   Accepted: 19978 D ...

  3. POJ 1008 Maya Calendar

    链接:http://poj.org/problem?id=1008 Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Subm ...

  4. BZOJ 1008 题解

    1008: [HNOI2008]越狱 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 7845  Solved: 3359[Submit][Status] ...

  5. HDU 4777 Rabbit Kingdom (2013杭州赛区1008题,预处理,树状数组)

    Rabbit Kingdom Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  6. 【BZOJ】1008: [HNOI2008]越狱(快速幂)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1008 刚开始看不会做啊,以为是dp,但是数据太大!!!所以一定有log的算法或者O1的算法,,,,还 ...

  7. PAT (Top Level) Practise 1008 Airline Routes(Tarjan模版题)

    1008. Airline Routes (35) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue Given a ...

  8. PAT乙级 1009. 说反话 (20)

    1009. 说反话 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 给定一句英语,要求你编写程序,将句中 ...

  9. PAT乙级 1008. 数组元素循环右移问题 (20)

    1008. 数组元素循环右移问题 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 一个数组A中存有N(N>0)个整数,在不允 ...

随机推荐

  1. The 2019 ICPC China Nanchang National Invitational and International Silk-Road Programming Contest - F.Sequence(打表+线段树)

    题意:给你一个长度为$n$的数组,定义函数$f(l,r)=a_{l} \oplus a_{l+1} \oplus...\oplus a_{r}$,$F(l,r)=f(l,l)\oplus f(l,l+ ...

  2. Android之收音机UI实现(转)

    源码: http://www.2cto.com/kf/201211/171417.html 最近在研究收音机的源码,本来想把收音机从源码中提取出来,做成一个单独的应用,但是,收音机需要底层的支持,所以 ...

  3. centos7一步一步搭建docker jenkins 及自定义访问路径重点讲解

    系统环境:centos7.7 (VMware中) 镜像image 版本:jenkins/jenkins (截止2020.01.10最新版) 参考文章:https://www.jianshu.com/p ...

  4. ardrino#串口控制led

    void setup() { pinMode(D6, OUTPUT); digitalWrite(D6,HIGH); Serial.begin(); } void loop() { String st ...

  5. linux#自启动脚本

    编写脚本: /etc/init.d/myscriptname # chkconfig: # description: 描述信息,描述信息,上面的90表示在众多开机启动脚本的优先级,10表示在众多关机启 ...

  6. 远程登陆ubantu服务器 .bashrc文件每次打开终端都需要source的问题

    通过创建的用户登录ubantu服务器时,.bashrc文件每次都要重新配置,要不然里面的配置如命令的简写如 ll 等就无法识别,本方法用于实现登录时自动执行.bashrc文件. 1.ubantu启动时 ...

  7. Codeforces 1304D. Shortest and Longest LIS

    根据题目,我们可以找最短的LIS和最长的LIS,找最短LIS时,可以将每一个increase序列分成一组,从左到右将最大的还未选择的数字填写进去,不同组之间一定不会存在s[i]<s[j]的情况, ...

  8. vb.net自学完整版

    https://m.book118.com/html/2016/1203/67671992.shtm

  9. jwt 认证

    目录 jwt 认证示意图 jwt 认证算法:签发与检验 drf 项目的 jwt 认证开发流程(重点) drf-jwt 框架基本使用 token 刷新机制(了解) jwt 认证示意图 jwt 优势 1 ...

  10. LUOGU P6034 Ryoku与最初之人笔记 简要题解

    比赛的时候有个地方忘记取模怒砍80,调了一下午Orz(虽然我总共貌似就打这个比赛半个多小时 我们一眼看到涉及到公约数/同余 和 xor,所以我们想到了一些关于xor的性质 a+b >= a xo ...