实习笔记-24

设备到设备文件传输

如果您的应用以 Android 11 或更高版本为目标平台,您将无法使用 allowBackup 属性停用应用文件的设备到设备迁移。系统会自动启用此功能。

不过,即使您的应用以 Android 11 或更高版本为目标平台,您也可以通过将 allowBackup 属性设为 false 来停用应用文件的云端备份和恢复。

非 SDK 接口限制

相机

媒体 intent 操作需要系统默认相机
从 Android 11 开始,只有预装的系统相机应用可以响应以下 intent 操作:

阅读更多

实验-使用动态优先权的进程调度算法模拟

1、实验目的

通过动态优先权算法的模拟加深对进程概念进程调度过程的理解。

2、实验内容

  1. 用C语言来实现对N个进程采用动态优先权优先算法的进程调度。
  2. 每个用来标识进程的进程控制块PCB用结构来描述,包括以下字段:
  • 进程标识数 ID。
  • 进程优先数 PRIORITY,并规定优先数越大的进程,其优先权越高。
  • 进程已占用的CPU时间CPUTIME。
  • 进程还需占用的CPU时间ALLTIME。当进程运行完毕时,ALLTIME变为0。•••• 进程的阻塞时间STARTBLOCK,表示当进程再运行STARTBLOCK个时间片后,将进入阻塞状态。
  • 进程被阻塞的时间BLOCKTIME,表示已足赛的进程再等待BLOCKTIME个时间片后,将转换成就绪状态。
  • 进程状态START。
  • 队列指针NEXT,用来将PCB排成队列。
  1. 优先数改变的原则:
阅读更多

实验-使用动态分区分配方式的模拟

1、实验目的

了解动态分区分配方式中使用的数据结构和分配算法,并进一步加深对动态分区存储管理方式及其实现过程的理解。

2、实验内容

  1. 用C语言分别实现采用首次适应算法和最佳适应算法的动态分区分配过程alloc( )和回收过程free( )。其中,空闲分区通过空闲分区链来管理:在进行内存分配时,系统优先使用空闲区低端的空间。
  2. 假设初始状态下,可用的内存空间为640KB,并有下列的请求序列:
    作业1申请130KB。
    作业2申请60KB。
    作业3申请100KB。
    作业2释放60KB。
    作业4申请200KB。
    作业3释放100KB。
    作业1释放130KB。
    作业5申请140KB。
    作业6申请60KB。
    作业7申请50KB。
    作业6释放60KB。

请分别采用首次适应算法和最佳适应算法,对内存块进行分配和回收,要求每次分配和回收后显示出空闲分区链的情况。

实验代码

阅读更多

实验-简单文件系统的实现

1、实验目的

通过具体的文件存储空间的管理、文件的物理结构、目录结构和文件操作的实现,加深对文件系统内部功能和实现过程的理解。

2、实验内容

  1. 在内存中开辟一个虚拟磁盘空间作为文件存储器,在上面实现一个简单单用户文件系统。退出时应该将该虚拟文件系统保存到磁盘上,以便下次可以再将它恢复到内存对虚拟磁盘空间中。
  2. 文件存储空间对分配可以采用显式链接分配或者其他的办法。
  3. 空闲空间的管理可以选择位示图或者其他的办法。如果采用位示图来管理文件存储空间,并采用显式链接分配方式,那么可以将位示图合并到FAT中。
  4. 文件目录结构采用多级目录结构。为了简单起见,可以不使用索引结点,其中的每个目录项应包含文件名、物理地址、长度等信息,还可以通过目录项实现对文件对读和写的保护。
  5. 要求提供以下有关的操作:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    √format:对文件存储器进行格式化,即按照文件系统对结构对虚拟磁盘空间进行布局,并在其上创建根目录以及用于管理文件存储空间等的数据结构。
    √mkdir:用于创建子目录;
    √rmdir:用于删除目录;
    √ls:用于显示目录;
    √cd:用于更改当前目录;
    √create:用于创建文件;
    √open:用于打开文件;
    √close:用于关闭文件;
    √write:用于写文件;
    √read:用于读文件
    √rm:用于删除文件。

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
#include <iostream>
#include <vector>
#include <iomanip>
#include <fstream>
using std::string;
using std::vector;
using std::cout;
using std::endl;
using std::cin;
using std::ifstream;
using std::ofstream;
using std::ios;
class FCB{
public:
int first_block;
string fileName;
int size;
int real_size;
FCB(int first_block0,const string &fileName0, int size0, int real_size0):
first_block(first_block0),
fileName(fileName0),
size(size0),
real_size(real_size0*4) {
}
}; //文件控制块
class DirItem { //文件树
string name;
vector<FCB*> files; //目录下的文件
vector<DirItem*> dirs; //目录下的文件夹,树节点
public:
DirItem(const string& name0):name(name0) {}
void addFile(int first_block, const string& fileName,int size, int real_size) {
for (auto i = files.begin(); i != files.end(); i++) {
if ((*i)->fileName == fileName) {
cout << "same file name" << endl;
return;
}
}
files.push_back(new FCB(first_block, fileName, size, real_size));
}
void addDir(DirItem* dir) {
dirs.push_back(dir);
}
vector<DirItem*> getDirs() {
return dirs;
}
vector<FCB*> getFiles() {
return files;
}
string getName() {
return name;
}
void del_file(const string& fileName) {
for (auto i = files.begin(); i != files.end(); i++) {
if ((*i)->fileName == fileName) {
files.erase(i);
break;
}
}
}
void del_dir(const string& fileName) {
for (auto i = dirs.begin(); i != dirs.end(); i++) {
if ((*i)->getName() == fileName) {
dirs.erase(i);
break;
}
}
}
void clear() {
for (DirItem* item : dirs) {
delete item;
}
for (FCB* item : files) {
delete item;
}
dirs.clear();
files.clear();
} //递归删除时用到,删除当前目录下的目录和文件的指针
};

class diskMgr { //磁盘
vector<int> blocks; //fat表
int n = 16;
int block_num = n*n;
int block_size = 4; //每块4B
int disk_capacity = block_num * block_size; //1M
vector<vector<int>> bit_map; //0空,1有,位视图
public:
vector<char> disk;
diskMgr() {
disk = vector<char>(disk_capacity, '\0');
blocks = vector<int>(block_num, -1);
bit_map = vector<vector<int>>(n, vector<int>(n, 0));
}
int getSize(int blockNum) {
int n = 0;
while (blockNum != -1) {
n++;
blockNum = blocks[blockNum];
}
return n;
} //当前块号开始的文件一个有多少块儿
int find_empty_block() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (bit_map[i][j] == 0) {
return n*i+j;
}
}
}
return -1;
}//找到一个空闲盘块,从位视图
void update_bit_map(int x, int notempty) {
int i = x / n,j = x % n;
bit_map[i][j] = notempty;
}//更新位视图
void del(int blockNum) {
while (blockNum != -1) {
for(int i = 0; i < block_size; i++) {
disk[blockNum * block_size + i] = '\0';
}
update_bit_map(blockNum, 0);
int t = blocks[blockNum];
blocks[blockNum] = -1;
blockNum = t;
}
} //删除文件
vector<char> read(int blockNum) {
vector<char> data;
while (blockNum != -1) {
for(int i = 0; i < block_size; i++) {
data.push_back(disk[blockNum * block_size + i]);
}
blockNum = blocks[blockNum];
}
return data;
} //读取文件
int write(vector<char> data) {
int first_block = find_empty_block(); //找到初始位置
if (first_block == -1) return -1;
int len = int(data.size());
int blockn = len%block_size == 0 ? len/block_size : len/block_size+1; //一共需要的盘块儿数
int next_block = first_block;
int temp = next_block;
int fix = (block_size - len % block_size) % block_size;

for (int i = 0; i < fix; ++i) { //数据长度对齐
data.push_back('*');
}
for (int i = 0; i < blockn; i++) { //存数据
if (temp == -1) {
break;
}
next_block = temp;
for (int j = 0; j < block_size; j++) {
disk[next_block*block_size+j] = data[i*block_size+j];
}
update_bit_map(next_block, 1);
temp = find_empty_block();
blocks[next_block] = temp;

}
blocks[next_block] = -1;
return first_block;
}

};
#define chart_head std::left << std::setw(len+1) << std::setfill('-') << ""
#define chart_cell "|" << std::left << std::setw(len) << std::setfill(' ')
class fileMgr {
DirItem * root; //根节点
diskMgr dm;//磁盘管理器
DirItem * cur; //当前命令行执的工作目录
string cur_path; //工作命令
DirItem* addmdir(DirItem * node, string name) {
DirItem* newNode = new DirItem(name);
node->addDir(newNode);
return newNode;
}
public:

fileMgr() {
root = new DirItem("/");
DirItem * temp = addmdir(addmdir(root, "apps"), "tencent");
addmdir(temp, "qq");
addmdir(temp, "qqgame");
addmdir(temp, "qqmusic");
temp = addmdir(root, "docs");
addmdir(temp, "words");
addmdir(temp, "ppts");
addmdir(temp, "excels");

root->addDir(new DirItem("pics"));
root->addDir(new DirItem("musics"));
cur = root;
cur_path = "/";
cout_hint();
} //初始化一些文件夹
void ls() {
int len = 20;
cout
<< chart_head << chart_head << chart_head << chart_head << endl
<< chart_cell << "file/dir name"
<< chart_cell << "type"
<< chart_cell << "size"
<< chart_cell << "real size" << "|" << std::endl
<< chart_head << chart_head << chart_head << chart_head << endl;
vector<DirItem*> dirs = cur->getDirs();
for (auto i = dirs.begin(); i != dirs.end(); i++) {
cout
<< chart_cell << (*i)->getName()
<< chart_cell << "directory"
<< chart_cell << "--"
<< chart_cell << "--" << "|" << std::endl;
}
vector<FCB*> files = cur->getFiles();
for (auto i = files.begin(); i != files.end(); i++) {
cout
<< chart_cell << (*i)->fileName
<< chart_cell << "file"
<< chart_cell << (*i)->size
<< chart_cell << (*i)->real_size << "|" << std::endl;
}
cout
<< chart_head << chart_head << chart_head << chart_head << endl;
cout_hint();
}
void cout_hint() {
cout << "\n" << cur_path << "> ";
} //输出命令行提示符
void cd(string name) {
if (name == "..") {
if(cur_path == "/") {
cout_hint();
} else {
if (*cur_path.rbegin() == '/') {
cur_path.pop_back();
}
cur_path = cur_path.substr(0, cur_path.rfind('/'));
if (cur_path.length() == 0) {
cur_path = "/";
}
cur = find_dir_node(cur_path);
cout_hint();
return;
}
}
DirItem* node = cur;
for(DirItem* item : node->getDirs()){
if (item->getName() == name) {
cur = item;
cur_path += name+"/";
cout_hint();
return;
}
}
cout << "no such dir";
cout_hint();
}
void cdn(string path) {
cur = find_dir_node(path);
if (*path.rbegin() != '/') {
path.push_back('/');
}
if (*path.begin() != '/') {
path = "/" + path;
}
cur_path = path;
cout_hint();
}
DirItem* find_dir_node(string path) {
if (path[0] == '/') {
path = path.substr(1, path.length()-1);
}
if (*path.rbegin() != '/') {
path.push_back('/');
}
int r = 0;
DirItem* node = root;
if (path == "/") return node;
while (r != -1) {
r = path.find('/');
if (r != -1) {
string dir = path.substr(0, r);
bool find = false;
for(DirItem* item : node->getDirs()){
if (item->getName() == dir) {
node = item;
find = true;
break;
}
}
if (!find) {
return nullptr;
}
path = path.substr(r+1, path.length() - r - 1);
} else {
break;
}
}
return node;
}
void create_file(const string& fileName, const vector<char>& data) {
DirItem *node = cur;
if (node != nullptr) {
int fb = dm.write(data);
if(fb == -1) {
cout << "no enough disk storage";
cout_hint();
}
int size = dm.getSize(fb);
node->addFile(fb, fileName, data.size(), size);
}
cout_hint();
}
void create_file(string path, const string& fileName, const vector<char>& data) {
DirItem *node = find_dir_node(path);
if (node != nullptr) {
int fb = dm.write(data);
int size = dm.getSize(fb);
node->addFile(fb, fileName, data.size(), size);
}
}
void create_dir(const string& dirName) {
if (cur != nullptr) {
cur->addDir(new DirItem(dirName));
}
cout_hint();
}
void create_dir(string path, const string& dirName) {
DirItem * node = find_dir_node(path);
if (node != nullptr) {
node->addDir(new DirItem(dirName));
}
}
void del_dir(DirItem* node) {
if (node != nullptr) {
for(FCB* fcb : node->getFiles()) {
dm.del(fcb->first_block);
node->del_file(fcb->fileName);
}
for(auto i : node->getDirs()) {
del_dir(i);
}
node->clear();
}
}
void del_dir(const string& fileName) {
if (cur != nullptr) {
for (auto i : cur->getDirs()) {
if(i->getName() == fileName) {
del_dir(i);
cur->del_dir(i->getName());
cout_hint();
return;
}
}
}
cout << "no such directory";
cout_hint();
}
void del_file(const string& fileName) {
DirItem*node = cur;
if (node != nullptr) {
for(FCB* fcb : node->getFiles()) {
if (fcb->fileName == fileName) {
dm.del(fcb->first_block);
node->del_file(fileName);
cout_hint();
return;
}
}
}
}
void del_file(string path, const string& fileName) {
DirItem*node = find_dir_node(path);
if (node != nullptr) {
for(FCB* fcb : node->getFiles()) {
if (fcb->fileName == fileName) {
dm.del(fcb->first_block);
node->del_file(fileName);
return;
}
}
}
}
void show(const vector<char>& v) {
for (char i : v) {
cout << i;
}
}
void read(const string& fileName) {
if (cur != nullptr) {
for(FCB* fcb : cur->getFiles()) {
if (fcb->fileName == fileName) {
vector<char> data = dm.read(fcb->first_block);
show(data);
cout_hint();
return;
}
}
}
cout << "file not found";
cout_hint();
}
vector<char> read(string path, const string& fileName) {
DirItem*node = find_dir_node(path);
if (node != nullptr) {
for(FCB* fcb : node->getFiles()) {
if (fcb->fileName == fileName) {
return dm.read(fcb->first_block);
}
}
}
return {};
}


};
int main() {


fileMgr fm;
/*ifstream Myfile2;
Myfile2.open("file_sys.disk",ios::binary);
//二进制打开,缺省为文本,ios::out,ios::in,文本输入输出用<<,>>
Myfile2.read((char *)&fm,sizeof(fileMgr));
Myfile2.close();*/
string ins, para;
while(cin >> ins) {
if(ins == "ls") {
fm.ls();
} else if(ins == "cd") {
cin >> para;
fm.cd(para);
} else if (ins == "read") {
cin >> para;
fm.read(para);
} else if (ins == "mkdir") {
cin >> para;
fm.create_dir(para);
} else if (ins == "rmdir") {
cin >> para;
fm.del_dir(para);
} else if (ins == "mkfile") {
cin >> para;
string c = "";
cout << "contents:\n";
string data;
while(c != "#") {
data += c;
std::getline(cin, c);
data += '\n';
}
int k = 0;
while (data[k] == '\n') k++;
data = data.substr(k, data.length()-k);
vector<char> vdata;
for(char i : data) {
vdata.push_back(i);
}
fm.create_file(para, vdata);
} else if (ins == "rmfile") {
cin >> para;
fm.del_file(para);
} else if (ins == "exit" || ins == "quit") {
break;
} else if (ins == "cdn") {
cin >> para;
fm.cdn(para);
} else {
string c;
std::getline(cin, c);
ins += " " + c;
system(ins.c_str());
cout << "unknown cmd:" << ins << endl;
fm.cout_hint();
}
}


/*ofstream file;
file.open("file_sys.disk",ios::binary);
//缓存的类型是 unsigned char *,需要类型转换
file.write((char *)&fm,sizeof(fileMgr)); //winServer为类对象
file.close();*/
return 0;
}
阅读更多

实验-请求调页存储管理方式的模拟

1、实验目的

通过对页面、页表、地址转换和页面置换过程的模拟,加深对请求调页系统的原理和实现过程的理解。

2、实验内容

  • 假设每个页面中可存放10条指令,分配给一作业的内存块数为4。
  • 用C语言模拟一作业的执行过程。该作业共有320条指令,即它的地址空间为32页,目前它的所有页都还未调入内存。在模拟过程中,如果所访问的指令已经在内存中,则显示其物理地址,并转下一条指令。如果所访问的指令还未装入内存,则发生缺页,此时需记录缺页的次数,并将相应页调入内存。如果4个内存块中均已装入该作业,则需进行页面置换。最后显示其物理地址,并转下一条指令。在所有320条指令执行完毕后,请计算并显示作业运行过程中发生的缺页率。
  • 置换算法:请分别考虑OPT、FIFO和LRU算法。
  • 作业中指令的访问次序按下述原则生成:

• 50%的指令是顺序执行的。
• 25%的指令是均匀分布在前地址部分。
• 25%的指令时均匀分布在后地址部分。

具体的实施办法是:

阅读更多

LeetCode-10

2020-07-25

Z 字形变换

AC代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Solution {
public:
string convert(string s, int numRows) {
if (numRows <= 1) {
return s;
}
int n = s.size();
string temp[numRows];
int t_numRows = 0;
int p = 0;
while(p < n) {
while(p < n && t_numRows < numRows) {
temp[t_numRows] += s[p];
p++;
t_numRows++;
}
t_numRows = numRows -2;
while (p < n && t_numRows > 0) {
temp[t_numRows] += s[p];
p++;
t_numRows--;
}
}
string res;
for(int i = 0 ; i < numRows; i++) {
res = res + temp[i];
}
return res;
}
};

优化思路

  1. 两层while循环多次判断p<n,效率底下,实际上只需要当t_numRows==0或t_numRows==numRows-1时改变方向即可

  2. 实际上需要的string数组长度是min(n, numRows)

    优化代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    class Solution {
    public:
    string convert(string s, int numRows) {
    if (numRows <= 1) {
    return s;
    }
    int n = int(s.size());
    int len = min(numRows, n);
    vector<string> temp(len);
    int t_numRows = 0;
    bool goingDown = false;
    for(int i = 0; i < n; i++) {
    temp[t_numRows] += s[i];
    if (t_numRows == 0 || t_numRows == numRows-1) {
    goingDown = !goingDown;
    }
    t_numRows += goingDown ? 1 :-1;
    }
    string res;
    for (int i = 0; i < len; i++) res += temp[i];
    return res;
    }
    };

    再次优化

    可以直接找新旧数列的数字关系,直接计算

    优化代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    class Solution {
    public:
    string convert(string s, int numRows) {
    if (numRows <= 1) {
    return s;
    }
    int len_s = int(s.size());
    int unit =(2*numRows-2);
    int n = len_s/unit;
    int remain = len_s%unit;
    string res(len_s, 0);
    for (int i = 0; i < len_s; i++) {
    int p = 0;
    if (i%unit == 0) {
    p = i/unit+1;
    } else {
    int r = i%unit + 1,c = i/unit+1;
    if (r > numRows) {
    r = unit-r+2;
    p = 1;
    } else if (r == numRows) {
    p = 1-c;
    }
    p += n + (n*2)*(r-2) + 2*(c-1) + min(r-1, remain)+1;
    if (remain > numRows) {
    p += max(r-(unit-remain+2),0);
    }
    }
    res[p-1] = s[i];
    }
    return res;
    }
    };

    最终成绩

    执行用时:8 ms, 在所有 C++ 提交中击败了98.89%的用户

    内存消耗:7.7 MB, 在所有 C++ 提交中击败了100.00%的用户

阅读更多

LeetCode-11

2020-07-27

55. 跳跃游戏

思路

  1. 对nums数组,令nums[i] += i,这样表示i位置最远可以走到的距离

  2. 算法

    从i = 0开始
    对于当前i,可以从0走到nums[i],选取0-nums[i]的最大值,如果最大值大于等于n-1,则可以到达最后,若小于,重复这个步骤,除非i=最大值,则不能到达最后

  3. 为了降低时间复杂度,创建一个数组v,v[i] = max(nums[k]), k = 0,1,…,i

AC代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Solution {
public:
bool canJump(vector<int>& nums) {
int n = int(nums.size());
for(int i = 0; i < n; i++) {
nums[i] += i;
}
vector<int> v;
int max = nums[0];
for(int i = 0; i < n; i++) {
if (nums[i] > max) {
max = nums[i];
}
v.push_back(max);
}
int i = 0;
while (i != v[i]) {
i = v[i];
if (i >= n-1) {
return true;
}
}
return false || n == 1;
}
};
阅读更多

PAT-Basic-1005

题目

卡拉兹(Callatz)猜想已经在1001中给出了描述。在这个题目里,情况稍微有些复杂。

当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推过程中遇到的每一个数。例如对 n=3 进行验证的时候,我们需要计算 3、5、8、4、2、1,则当我们对 n=5、8、4、2 进行验证的时候,就可以直接判定卡拉兹猜想的真伪,而不需要重复计算,因为这 4 个数已经在验证3的时候遇到过了,我们称 5、8、4、2 是被 3“覆盖”的数。我们称一个数列中的某个数 n 为“关键数”,如果 n 不能被数列中的其他数字所覆盖。

现在给定一系列待验证的数字,我们只需要验证其中的几个关键数,就可以不必再重复验证余下的数字。你的任务就是找出这些关键数字,并按从大到小的顺序输出它们。

输入格式:

每个测试输入包含 1 个测试用例,第 1 行给出一个正整数 K (<100),第 2 行给出 K 个互不相同的待验证的正整数 n (1<n≤100)的值,数字间用空格隔开。

阅读更多

PAT-Basic-1014

题目

大侦探福尔摩斯接到一张奇怪的字条:我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm。大侦探很快就明白了,字条上奇怪的乱码实际上就是约会的时间星期四 14:04,因为前面两字符串中第 1 对相同的大写英文字母(大小写有区分)是第 4 个字母 D,代表星期四;第 2 对相同的字符是 E ,那是第 5 个英文字母,代表一天里的第 14 个钟头(于是一天的 0 点到 23 点由数字 09、以及大写字母 AN 表示);后面两字符串第 1 对相同的英文字母 s 出现在第 4 个位置(从 0 开始计数)上,代表第 4 分钟。现给定两对字符串,请帮助福尔摩斯解码得到约会的时间。

输入格式:

输入在 4 行中分别给出 4 个非空、不包含空格、且长度不超过 60 的字符串。

输出格式:

在一行中输出约会的时间,格式为 DAY HH:MM,其中 DAY 是某星期的 3 字符缩写,即 MON 表示星期一,TUE 表示星期二,WED 表示星期三,THU 表示星期四,FRI 表示星期五,SAT 表示星期六,SUN 表示星期日。题目输入保证每个测试存在唯一解。

阅读更多

PAT-Basic-1015

题目

宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人。凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人。”
现给出一批考生的德才分数,请根据司马光的理论给出录取排名。

输入格式:

输入第一行给出 3 个正整数,分别为:N(≤10^5),即考生总数;L(≥60),为录取最低分数线,即德分和才分均不低于 L 的考生才有资格被考虑录取;H(<100),为优先录取线——德分和才分均不低于此线的被定义为“才德全尽”,此类考生按德才总分从高到低排序;才分不到但德分到线的一类考生属于“德胜才”,也按总分排序,但排在第一类考生之后;德才分均低于 H,但是德分不低于才分的考生属于“才德兼亡”但尚有“德胜才”者,按总分排序,但排在第二类考生之后;其他达到最低线 L 的考生也按总分排序,但排在第三类考生之后。

随后 N 行,每行给出一位考生的信息,包括:准考证号 德分 才分,其中准考证号为 8 位整数,德才分为区间 [0, 100] 内的整数。数字间以空格分隔。

输出格式:

阅读更多