PAT A1005-1008
A 1005 Spell It Right (20 point(s))
25分的题目,比较简单,注意N的范围,用字符串处理即可。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring> using namespace std; int main()
{
const char * numStr[]={"zero","one","two","three","four","five","six","seven","eight","nine"};
string tmpStr;
cin >> tmpStr;
int sum = ;
for(int i = ; i < tmpStr.size(); ++ i)
sum += tmpStr[i]-'';
char charArray[];
sprintf(charArray, "%d", sum);
for(int i = ; i < strlen(charArray); ++ i)
{
if(i > ) printf(" ");
printf("%s", numStr[charArray[i]-'']);
}
return ;
}
A 1006 1006 Sign In and Sign Out (25 point(s))
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring> using namespace std; int main()
{
int M, tmpHour, tmpMinute, tmpSecond, unLockTime=*, lockTime=-;
cin >> M;
string tmpStr, unLockId, lockId;
for(int i = ; i < M; ++i)
{
cin >> tmpStr;
scanf("%d:%d:%d", &tmpHour, &tmpMinute, &tmpSecond);
tmpHour = tmpHour*+tmpMinute*+tmpSecond;
if(tmpHour < unLockTime)
{
unLockId = tmpStr;
unLockTime = tmpHour;
}
scanf("%d:%d:%d", &tmpHour, &tmpMinute, &tmpSecond);
tmpHour = tmpHour*+tmpMinute*+tmpSecond;
if(tmpHour > lockTime)
{
lockId = tmpStr;
lockTime = tmpHour;
}
}
cout << unLockId << " " << lockId;
return ;
}
A 1007 Maximum Subsequence Sum (25 point(s))
经典的最大子序列和问题,注意 全为负数 和 只有负数和0 这两种情况即可,理不清题意可能会有一两个点过不去。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring> using namespace std; int main()
{
int K, tmpSt, resSt, resEnd, tmpNum, sum = -, maxSum = -;
cin >> K;
bool negFlag = true;
for(int i = ; i < K; ++ i)
{
cin >> tmpNum;
if(i==)
resSt = tmpNum;
if(tmpNum >= )
negFlag = false;
if(sum < )
{
sum = ;
tmpSt = tmpNum;
}
sum += tmpNum;
if(sum > maxSum)
{
maxSum = sum;
resSt = tmpSt;
resEnd = tmpNum;
}
}
if(negFlag)
cout << << " " << resSt << " " << tmpNum;
else
cout << maxSum << " " << resSt << " " << resEnd;
return ;
}
A 1008 Elevator (20 point(s))
一个直观的数学计算问题
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring> using namespace std; int main()
{
int N, tmpNum, tmpFloor = , sum = ;
cin >> N;
for(int i = ; i < N; ++ i)
{
cin >> tmpNum;
if(tmpFloor < tmpNum)
sum += + *(tmpNum - tmpFloor);
else
sum += + *(tmpFloor - tmpNum);
tmpFloor = tmpNum;
}
cout << sum;
return ;
}
PAT A1005-1008的更多相关文章
- PAT 乙级 1008
题目 题目地址:PAT 乙级 1008 思路 本题需要注意的一点是当 m > n 的时候会出现逻辑性的错误,需要在 m > n 情况下对m做模运算,即 m % n 代码 #include ...
- PAT乙级 1008. 数组元素循环右移问题 (20)
1008. 数组元素循环右移问题 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 一个数组A中存有N(N>0)个整数,在不允 ...
- [C++]PAT乙级1008.数组元素循环右移问题 (20/20)
/* 1008. 数组元素循环右移问题 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 一个数组A中存有N(N>0)个整数, ...
- PAT Basic 1008
1008 数组元素循环右移问题 (20 分) 一个数组A中存有N(>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(≥0)个位置,即将A中的数据由(A0A1⋯AN ...
- PAT 乙级 1008 数组元素循环右移问题 (20) C++版
1008. 数组元素循环右移问题 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 一个数组A中存有N(N>0)个整数,在不允 ...
- PAT 甲级 1008 Elevator (20)(代码)
1008 Elevator (20)(20 分) The highest building in our city has only one elevator. A request list is m ...
- PAT甲 1008. Elevator (20) 2016-09-09 23:00 22人阅读 评论(0) 收藏
1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...
- PAT乙级1008
1008 数组元素循环右移问题 (20 分) 一个数组A中存有N(>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(≥0)个位置,即将A中的数据由(A0A1⋯A ...
- PAT 甲级 1008 Elevator (20)(20 分)模拟水题
题目翻译: 1008.电梯 在我们的城市里,最高的建筑物里只有一部电梯.有一份由N个正数组成的请求列表.这些数表示电梯将会以规定的顺序在哪些楼层停下.电梯升高一层需要6秒,下降一层需要4秒.每次停下电 ...
- 【PAT】1008. 数组元素循环右移问题 (20)
1008. 数组元素循环右移问题 (20) 一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A0A1……AN- ...
随机推荐
- 在linux上建立多个ORACLE的实例
1.打开终端,输入如下的命令: [root@ptest4 ~]# export DISPLAY=localhost:1 [root@ptest4 ~]# xhost + 2.切换 ...
- 整合 nginx php-fpm
start 继上一篇 整合两个images 完成 LNMP github https://github.com/shiphp/nginx-env 稍加修改 vim dockerfile ...
- 20190108PLC学习心得
应该是数据类型不对 F1查看了帮助文件以后 ,看到 LD应该是用指针类型的数据 改正以后 LD0下的红线消失了 . 绿色 代表没有给 符号 定义 地址 假设 我现在给 符号 字节数 ...
- HDU - 6198 number number number(规律+矩阵快速幂)
题意:已知F0 = 0,F1 = 1,Fn = Fn - 1 + Fn - 2(n >= 2), 且若n=Fa1+Fa2+...+Fak where 0≤a1≤a2≤⋯≤a,n为正数,则n为mj ...
- Python 实现类似range函数
需求:写一个属于你自己的 frange函数,frange与range类似,一样的参数规则,但是每一项必须要是float类型 实现: 注意点,如何判断stop是否有参数传入,这里使用空字符判断,如fra ...
- jquery实现常用UI布局
tab html <div class="tab"> <ul class="tab-title"> <li class=" ...
- 二十五、SAP中输出一条横线
一.我们代码如下,这个是不输出横线的时候 效果如下 二.输出横线的代码如下 效果如下,多出一条横线
- 干货分享:Research Essay写作规范详解
同学们在刚到国外时觉得一切都很新鲜,感觉到处都在吸引着他们,但是大部分留学生在刚碰到Research Essay便是一头包.其实Research Essay也没有想象中的那么难,只是留学生们初次接触, ...
- 实验吧-隐写术-黑与白(二)(反转+五笔+Image steganography)
反转有二:颜色反转.文件名反转 文件名这么乱,毫无规律,好奇怪,进行反转后发现是:steganography(就是隐写术的意思),这还是个图片文件,有一款工具正好叫Image steganograph ...
- 5分钟搞懂:基于token的用户认证
https://www.qikegu.com/easy-understanding/880 用户认证 用户认证或者说用户登录是确认某人确实是某人的过程,生活中靠身份证,网络上就要靠账号和密码.用户提供 ...