P 1008 说反话
转跳点:
这道题我记得谷歌 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 说反话的更多相关文章
- HDOJ 1008. Elevator 简单模拟水题
Elevator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- poj 1008:Maya Calendar(模拟题,玛雅日历转换)
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 64795 Accepted: 19978 D ...
- POJ 1008 Maya Calendar
链接:http://poj.org/problem?id=1008 Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Subm ...
- BZOJ 1008 题解
1008: [HNOI2008]越狱 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 7845 Solved: 3359[Submit][Status] ...
- HDU 4777 Rabbit Kingdom (2013杭州赛区1008题,预处理,树状数组)
Rabbit Kingdom Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- 【BZOJ】1008: [HNOI2008]越狱(快速幂)
http://www.lydsy.com/JudgeOnline/problem.php?id=1008 刚开始看不会做啊,以为是dp,但是数据太大!!!所以一定有log的算法或者O1的算法,,,,还 ...
- PAT (Top Level) Practise 1008 Airline Routes(Tarjan模版题)
1008. Airline Routes (35) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue Given a ...
- PAT乙级 1009. 说反话 (20)
1009. 说反话 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 给定一句英语,要求你编写程序,将句中 ...
- PAT乙级 1008. 数组元素循环右移问题 (20)
1008. 数组元素循环右移问题 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 一个数组A中存有N(N>0)个整数,在不允 ...
随机推荐
- Linux centosVMware mysql用户管理、常用sql语句、mysql数据库备份恢复
一.mysql用户管理 grant all on *.* to 'user1'@‘127.0.0.1’ identified by 'mimA123'; 创建user1用户 使用user1登录 /us ...
- MCM(矩阵链乘法)
这是<算法导论>动态规划中的一个问题.问题简述如下:我们在求解矩阵相乘时通常会有一个最优括号方案来对矩阵进行顺序相乘,这样会减少大量的计算时间. 我们知道矩阵A.B相乘,只能是当矩阵A的列 ...
- Codeforces 1260 ABC
DEF 题对于 wyh 来说过于毒瘤,十分不可做. A. Heating Description: 给定\(a,b\),将\(b\)分成至少\(a\)个正整数,使这些正整数的平方和最小. Soluti ...
- Tomcat 8 Invalid character found in the request target. The valid characters are defined in RFC 3986
终极解决方案: Invalid character found in the request target. The valid characters are defined in RFC 3986 ...
- java实现经典排序算法
前言 博主最近在恶补基础知识,算法必然是必不可少的,那么就从经典排序算法开始吧!(图源网络,侵删),没有列出全部,因为在期末考试囧 代码太多,就只显示了最关键的部分 1. 冒泡排序 实现思路: (1) ...
- html弹出框播放视频
<a data-toggle="modal" data-target=".bs-example-modal-lg">模态框</a> &l ...
- 任意两点之间的最短路(floyed)
F.Moving On Firdaws and Fatinah are living in a country with nn cities, numbered from 11 to nn. Each ...
- Python字符串(二)
四.类型转换 1. 基本语法: 类型名(数据) --- 将指定数据转换成指定类型 说明:类型名 -任何python支持的,或者自定的类型都可以数据 -需要转换的对象,类型不同要求可能不一样 2. 转换 ...
- (转)C#的 GC工作原理基础
作为一位C++出身的C#程序员,我最初对垃圾收集(GC)抱有怀疑态度,怀疑它是否能够稳定高效的运作:而到了现在,我自己不得不说我已经逐渐习惯并依赖GC与我的程序“共同奔跑”了,对“delete”这个习 ...
- HDU5943 Kingdom of Obsession 题解
题意 有 \(n\) 个数 \(s+1\ldots s+n\),求是否能将这 \(n\) 个数放到 \(1\ldots n\) 上,且当令原数为 \(x\),放到 \(y\) 位置时有 \(x \mo ...