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. 【学CG系列】web之审查元素

    一.审查元素的作用 审查元素(你的F12)可以做到定位网页元素.实时监控网页元素属性变化的功能,可以及时调试.修改.定位.追踪检查.查看嵌套 ,修改样式和查看js动态输出信息,是开发人员得心应手的好工 ...

  2. mapper语句的一些问题,union连表查询和mapper中根据条件不同采用不同语句的查询问题

    根据业务要求,不同表查出来的内容天需要一起展示出来,并且还有分页之类的,不同表查询字段也不完全相同,这样就有一个问题,不同表如何接合在一起,不同字段怎么办? 这个问题就需要用到union联合查询,并将 ...

  3. 077-PHP数组删除元素

    <?php $arr=array(98,'hello',67,'A',85,NULL); //定义一个数组 echo '删除元素之前数组中的元素个数为:'.count($arr); //输出数组 ...

  4. 控制台连接oracle11g报ORA-12560异常

    oracle11g R2 64bit oracleClient 11.2 32bit PL/SQL Developer 11.0.2 32bit 今天发现了一个奇怪的现象,如图: 后来发现机器上既有s ...

  5. 说说lock到底要锁谁?

    波安搬... http://www.cnblogs.com/wolf-sun/p/4209521.html ---------------------------------------------- ...

  6. Codeforces Round #616 (Div. 2)

    地址:http://codeforces.com/contest/1291 A题就不写解析了,就是给一个数,是不是本身满足这个条件或者删除某些数字来达到这个条件:奇数,各个位上的数字加起来是偶数. # ...

  7. mac安装vue没有使用权限不足

    ➜  ~ vue init webpack frontend ⠋ downloading template /usr/local/lib/node_modules/vue-cli/node_modul ...

  8. python 的第一个界面程序(PyQt5)

    这里用到了python的一个第三qt库PyQt5,API与qt几乎完全一样(科学严谨下...) from PyQt5.QtWidgets import QApplication, QMainWindo ...

  9. mysql 锁表的处理方式

    MySQL错误:ERROR 1205 (HY000): Lock wait timeout   处理方案:   执行mysql命令:show full processlist;   然后找出插入语句的 ...

  10. 碎碎念(DP)

    链接:https://ac.nowcoder.com/acm/contest/3006/F来源:牛客网 题目描述 在ACM比赛里,除了CE以外都是有效的提交.每一个提交都会有其评测的结果,或是AC,或 ...