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的更多相关文章

  1. PAT 乙级 1008

    题目 题目地址:PAT 乙级 1008 思路 本题需要注意的一点是当 m > n 的时候会出现逻辑性的错误,需要在 m > n 情况下对m做模运算,即 m % n 代码 #include ...

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

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

  3. [C++]PAT乙级1008.数组元素循环右移问题 (20/20)

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

  4. PAT Basic 1008

    1008 数组元素循环右移问题 (20 分) 一个数组A中存有N(>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(≥0)个位置,即将A中的数据由(A​0​​A​1​​⋯A​N ...

  5. PAT 乙级 1008 数组元素循环右移问题 (20) C++版

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

  6. PAT 甲级 1008 Elevator (20)(代码)

    1008 Elevator (20)(20 分) The highest building in our city has only one elevator. A request list is m ...

  7. 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 ...

  8. PAT乙级1008

    1008 数组元素循环右移问题 (20 分)   一个数组A中存有N(>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(≥0)个位置,即将A中的数据由(A​0​​A​1​​⋯A ...

  9. PAT 甲级 1008 Elevator (20)(20 分)模拟水题

    题目翻译: 1008.电梯 在我们的城市里,最高的建筑物里只有一部电梯.有一份由N个正数组成的请求列表.这些数表示电梯将会以规定的顺序在哪些楼层停下.电梯升高一层需要6秒,下降一层需要4秒.每次停下电 ...

  10. 【PAT】1008. 数组元素循环右移问题 (20)

    1008. 数组元素循环右移问题 (20) 一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A0A1……AN- ...

随机推荐

  1. Python3 格式化输出

    Python3 格式化输出 今天用字符串功能的时候,我突然忘记了格式化输出的方式X﹏X.所以赶紧恶补一下. 1.打印字符串 print("My name is %s" %(&quo ...

  2. ROS常用库(一) fake_localization

    wiki是最好的学习资料,以下直接参考了wiki官网.另外po出官网网址,建议英语较好的朋友之接看原版 http://wiki.ros.org/fake_localization 概述 fake_lo ...

  3. Vulkan 之 Synchronization

    1.2之前定的版本采用 vkSemaphore和vkFence来进行同步, VkSemaphore allowed applications to synchronize operations acr ...

  4. 10.swoole学习笔记--进程队列通信

    <?php //进程仓库 $workers=[]; //最大进程数 $worker_num=; //批量创建进程 ;$i<$worker_num;$i++){ //创建子进程 $proce ...

  5. 061-PHP函数定义默认参数

    <?php function add($x=2,$y=3){ //定义函数并设置默认参数 return $x+$y; } echo add(); //不传入参数调用add函数add(2,3) e ...

  6. phpStudy配置站点解决各种不能访问问题(本地可www.xx.com访问)

    1.配置站点:打开phpStudy->其他选项菜单->站点域名管理 2.配置站点:打开phpStudy->其他选项菜单->打开hosts(www访问重点) 3.在apache的 ...

  7. kubernter相关内容

    1. Kubernetes 第一章:互联网架构的演变 随着1946年世界上第一台电子计算机的问世网络就随之出现了,只不过当初只是为了解决多个终端之间的连接,这就是局域网的雏形.后来,随着美国国防部高级 ...

  8. mac安装和启动mongodb

    使用使用 brew安装mongodb 可以使用 OSX 的 brew 来安装 mongodb: sudo brew install mongodb 如果要安装支持 TLS/SSL 命令如下: sudo ...

  9. POJ 3663:Costume Party

    Costume Party Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12607   Accepted: 4977 De ...

  10. Q3狂揽3亿美元净利润的特斯拉会让国内电动汽车厂商喜极而泣吗?

    作为电动汽车行业的标杆,特斯拉无疑是国内电动汽车厂商发展进程中重要的参考对象.而前段时间特斯拉身上出现的产能受阻.私有化风波.马斯克卸任董事长一职等事件,着实让国产电动汽车厂商惊出一身冷汗.毕竟如果特 ...