转跳点:  

这道题我记得谷歌 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. keil遇到hardfault时原因的查找

    当硬件仿真遇到hardfault会进入响应的中断软件陷阱中void HardFault_Handler(void),此时通过view-registers中的 1 如果STACK=MSP,则查看SP的堆 ...

  2. 【PAT甲级】1014 Waiting in Line (30 分)(队列维护)

    题面: 输入四个正整数N,M,K,Q(N<=20,M<=10,K,Q<=1000),N为银行窗口数量,M为黄线内最大人数,K为需要服务的人数,Q为查询次数.输入K个正整数,分别代表每 ...

  3. in comment after two dashes (--) next character must be > not - (position: START_TAG seen ...

    Error executing Maven. in comment after two dashes (--) next character must be > not - (position: ...

  4. [原]OpeanLayers3 For ArcGIS MapServer

    由于OpenLayers3比较新,百度能找到的demo很少,自己不得不参考官方给出的Examples来依葫芦画瓢了,地图服务采用的局方给的ArcGIS MapServer,先上图: 这个例子是按照官方 ...

  5. Kafka 启动报错java.io.IOException: Can't resolve address.

    阿里云上 部署Kafka 启动报错java.io.IOException: Can't resolve address. 本地调试的,报错 需要在本地添加阿里云主机的 host 映射   linux ...

  6. 在idea中设置指向源代码(scala)

    1.到官网下载scala源代码 点击如下链接下载源码:http://www.scala-lang.org/download/all.html 选择需要的版本点击进行下载,我选择的是2.11.8版本,如 ...

  7. 科软-信息安全实验1-ICMP重定向

    目录 一 前言 二 Talk is cheap, show me the code 三 效果演示 四 遇到的问题&解决 一 前言 文章不讲解理论知识哈,想学习理论知识的,认真听课

  8. VS2010如何进行程序调试

    VS2010如何进行程序调试 一.前言 对于初步学习C++的朋友,程序的调试是一项必备的技能.尤其是像C++这样难学的语言,程序调试的基本方法更是至关重要.毕竟,谁也不想自己幸幸苦苦一天敲出来的代码就 ...

  9. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 表格:边框表格

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  10. Address localhost:1099 is already in use(IDEA启动Tomcat报错1099 is already in use)

    IDEA中启动Tomcat报错,Error running Tomcat7.0.52: Address localhost:1099 is already in use 或者是 java.rmi.se ...