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- ...
随机推荐
- win上java1.7和1.8版本修改环境变量无效.md
网上找了很多办法都没用. 解决办法: 看看自己 "系统环境变量" 中是不是有 "C:\ProgramData\Oracle\Java\javapath" 这项配 ...
- MongoDB_02简介
MongoDB简介 MongoDB是一个开源,高性能,无模式的文档型数据库. 它支持的数据结构非常松散,是一种类似于JSON的格式叫BSON,所以他既可以存储比较复杂的数据类型,又相当的灵活. Mon ...
- MongoDB 副本集搭建
搭建mongodb副本集 [root@ mongodb]# cd /u02 [root@ u02]# mkdir -p mongodb/data_2777 [root@ u02]# mkdir -p ...
- DRF项目之通过业务逻辑选择数据集和序列化器
在REST后台开发中,我们需要通过业务逻辑来选择数据集或者序列化器. 选择数据集: # 重写get_queryset实现通过业务逻辑选择指定数据集 def get_queryset(self): '' ...
- Bug 佛祖镇楼
原文链接:https://www.cnblogs.com/xdp-gacl/p/4198935.html // _ooOoo_ // o8888888o // 88" . "88 ...
- 干货分享:深度解析Supplement Essay写作
今天Hotessay小编给同学们介绍下附加文书的创作思路.因为附加文书基本上都是短essay,所以简洁才是硬道理! 通常,我们可以把美国大学的附加文书分为以下几类: 1.Tell us about y ...
- 干货分享:Research Essay写作规范详解
同学们在刚到国外时觉得一切都很新鲜,感觉到处都在吸引着他们,但是大部分留学生在刚碰到Research Essay便是一头包.其实Research Essay也没有想象中的那么难,只是留学生们初次接触, ...
- 第十三篇Django Logging配置样例
第十三篇Django Logging配置样例 阅读目录(Content) Django 日志配置模板 官方链接 Django Logging Django 日志配置模板 LOGGING = { 've ...
- JDBC批处理方法
每次新建Connection的时候相当于建了一座桥,每次一辆车(PreparedStatement)运送货物(ResultSet)成本太高! 每次都建立网络连接的时间远远大于本地的时间,为了处理大量的 ...
- 完美的代价(swap成回文串、贪心)
Description 回文串,是一种特殊的字符串,它从左往右读和从右往左读是一样的.小龙龙认为回文串才是完美的. 现在给你一个串,它不一定是回文的,请你计算最少的交换次数使得该串变成一个完美的回文串 ...