A 1015 Reversible Primes

  看清题意即可。给的数是十进制的,需要先判断是不是素数,然后按照给定进制转化成字符串后进行翻转,最后再转化为十进制并判断是否为素数。

 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
using namespace std; int N, D;
char numStr[];
bool isPrime(int tmpNum)
{
if(tmpNum < )
return false;
int maxNum = sqrt(1.0*tmpNum);
for(int i = ; i <= maxNum; ++ i)
if(tmpNum % i == )
return false;
return true;
}
int strToNum()
{
int len = strlen(numStr), tmpNum = ;
for(int i = ; i < len; ++ i)
{
tmpNum = tmpNum*D + numStr[i]-'';
}
return tmpNum;
}
int main()
{
int tmpNum;
while(scanf("%d%d", &N, &D) != EOF && N >= )
{
if(!isPrime(N))
{
cout << "No" << endl;
continue;
}
for(int i = ; N > ; ++ i)
{
numStr[i] = N % D + '';
N /= D;
numStr[i+] = '\0';
}
tmpNum = strToNum();
if(!isPrime(tmpNum))
cout << "No" << endl;
else
cout << "Yes" << endl;
}
return ;
}

A 1016 1016 Phone Bills

 因为存在无效的记录,所以需要将他们先进行配对。处理方法是:按照名字和时间进行排序,然后筛选出所需要的记录再进行下一步处理。

 超时问题:每一个有效时间段的话费计算需要尽量减少计算量。

以下是柳婼精简的代码:

 #include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
struct node {
string name;
int status, month, time, day, hour, minute;
};
bool cmp(node a, node b) {
return a.name != b.name ? a.name < b.name : a.time < b.time;
}
double billFromZero(node call, int *rate) {
double total = rate[call.hour] * call.minute + rate[] * * call.day;
for (int i = ; i < call.hour; i++)
total += rate[i] * ;
return total / 100.0;
}
int main() {
int rate[] = {}, n;
for (int i = ; i < ; i++) {
scanf("%d", &rate[i]);
rate[] += rate[i];
}
scanf("%d", &n);
vector<node> data(n);
for (int i = ; i < n; i++) {
cin >> data[i].name;
scanf("%d:%d:%d:%d", &data[i].month, &data[i].day, &data[i].hour, &data[i].minute);
string temp;
cin >> temp;
data[i].status = (temp == "on-line") ? : ;
data[i].time = data[i].day * * + data[i].hour * + data[i].minute;
}
sort(data.begin(), data.end(), cmp);
map<string, vector<node> > custom;
for (int i = ; i < n; i++) {
if (data[i].name == data[i - ].name && data[i - ].status == && data[i].status == ) {
custom[data[i - ].name].push_back(data[i - ]);
custom[data[i].name].push_back(data[i]);
}
}
for (auto it : custom) {
vector<node> temp = it.second;
cout << it.first;
printf(" %02d\n", temp[].month);
double total = 0.0;
for (int i = ; i < temp.size(); i += ) {
double t = billFromZero(temp[i], rate) - billFromZero(temp[i - ], rate);
printf("%02d:%02d:%02d %02d:%02d:%02d %d $%.2f\n", temp[i - ].day, temp[i - ].hour, temp[i - ].minute, temp[i].day, temp[i].hour, temp[i].minute, temp[i].time - temp[i - ].time, t);
total += t;
}
printf("Total amount: $%.2f\n", total);
}
return ;
}

PAT A1015-1016的更多相关文章

  1. PAT甲级1016. Phone Bills

    PAT甲级1016. Phone Bills 题意: 长途电话公司按以下规定向客户收取费用: 长途电话费用每分钟一定数量,具体取决于通话时间.当客户开始连接长途电话时,将记录时间,并且客户挂断电话时也 ...

  2. PAT——乙级1016

    乙级PAT的1016 乙级的题相对比较简单,我也是主要联系写代码的格式,而不是联系算法. 1016 部分A+B (15 point(s)) 正整数 A 的“D​A​​(为 1 位整数)部分”定义为由  ...

  3. PAT A 1016. Phone Bills (25)【模拟】

    题目:https://www.patest.cn/contests/pat-a-practise/1016 思路:用结构体存储,按照名字和日期排序,然后先判断是否有效,然后输出,时间加减直接暴力即可 ...

  4. PAT乙级 1016. 部分A+B (15) C语言实现

    1016. 部分A+B (15) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 正整数A的“DA(为1位整数)部 ...

  5. PAT Basic 1016

    1016 部分A+B (15 分) 正整数 A 的“D​A​​(为 1 位整数)部分”定义为由 A 中所有 D​A​​ 组成的新整数 P​A​​.例如:给定 A=3862767,D​A​​=6,则 A ...

  6. PAT乙级 1016. 部分A+B (15)

    题目传送:https://www.patest.cn/contests/pat-b-practise/1016 正整数A的“DA(为1位整数)部分”定义为由A中所有DA组成的新整数PA.例如:给定A ...

  7. PAT乙级1016

    1016 部分A+B (15 分)   正整数 A 的“D​A​​(为 1 位整数)部分”定义为由 A 中所有 D​A​​ 组成的新整数 P​A​​.例如:给定 A=3862767,D​A​​=6,则 ...

  8. 【PAT】1016 部分A+B(15 分)

    1016 部分A+B(15 分) 正整数 A 的“D​A​​(为 1 位整数)部分”定义为由 A 中所有 D​A​​ 组成的新整数 P​A​​.例如:给定 A=3862767,D​A​​=6,则 A  ...

  9. pat甲级1016

    1016 Phone Bills (25)(25 分) A long-distance telephone company charges its customers by the following ...

  10. PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)

    1016 Phone Bills (25 分)   A long-distance telephone company charges its customers by the following r ...

随机推荐

  1. Luogu P3263 [JLOI2015]有意义的字符串

    Link 设\(e=\frac{b+\sqrt d}2,i=\frac{b-\sqrt d}2\). 显然\(f_n=e^n+i^n\)是一个整数,且\(f_n=(e+i)f_{n-1}+eif_{n ...

  2. Windows 10长脸了!

    Windows 10一直毁誉参半,但是在微软的持续升级完善之下,同时随着时间的流逝,已经顺利成为全球第一大桌面操作系统,并开始逐渐甩开Windows 7,全球设备安装量已经达到约8亿部. 根据最新的S ...

  3. oracle根据一张表更新另外一张表

    知道是两张表进行更新,之前作过mysql的,直接就写了: update a,b set a.code = b.code wehre a.id = b.id 然后就报错了,上网查了下知道oracle不能 ...

  4. 038、Java中逻辑运算之非运算“!”

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  5. 007.Delphi插件之QPlugins,插件的卸载和重新加载

    效果图如下,可以反复卸载和重新加载.QPlugins这个插件,还没弄明白,摸索着跟着DEMO写 主窗口代码如下 unit Frm_Main; interface uses Winapi.Windows ...

  6. 洛谷题解P1047 校门外的树

    题目描述 某校大门外长度为L的马路上有一排树,每两棵相邻的树之间的间隔都是1米.我们可以把马路看成一个数轴,马路的一端在数轴0的位置,另一端在L的位置:数轴上的每个整数点,即0,1,2,…,L,都种有 ...

  7. leetcode1161 Maximum Level Sum of a Binary Tree

    """ BFS遍历题,一遍AC Given the root of a binary tree, the level of its root is 1, the leve ...

  8. 修正png

    这是修正+取MD5的方法 function MD5FileTextPng(filename: AnsiString): AnsiString; var buf: ..MAX_PATH - ] of C ...

  9. HTML的文档结构与语法(二)

    3.7 超链接标记 语法:<a 属性=“值”>对当前链接的描述</a>     作用:网页进行跳转 常用的属性: Href:链接的网址或ip或地址    值:就是具体的地址 T ...

  10. sendgrid 批量发送邮件,收件栏只显示当前用户的方案

    需求:批量发送邮件,用户可能看到其他用户的邮箱地址,之前用BBC发送,但问题是接收地址是同一个. 官方解决方案:https://sendgrid.kke.co.jp/docs/Tutorials/A_ ...