解题思路:
不知为什么一直运行错误,数组也开足够大了,用蓝桥杯官方数据是AC的
注意事项:
参考代码:
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> #include <algorithm> #include <stdio.h> #define N 150000 using namespace std; bool vis[N + 2]; int newDoc() { int i = 1; for (i = 1; i < N; i++) { if (!vis[i]) { vis[i] = true; break; } } return i; } bool delDoc(int n) { bool status = false; if (vis[n]) { status = true; vis[n] = false; } return status; } int toNum(string str) { int num = 0; for (string::iterator it = str.begin(); it < str.end(); it++) { num = num * 10 + (*it - '0'); } return num; } int main(int argc, char** argv) { int t = 0; cin >> t; getchar(); for (int i = 0; i < t; i++) { string command; getline(cin, command); if (command == "New") { int doc = newDoc(); cout << doc << endl; } else { int docNumPos = 0; if ((docNumPos = command.find(" ")) != string::npos)//多位数 { string numStr = command.substr(docNumPos + 1, command.length() - 1 - docNumPos); int docNum = toNum(numStr); if (delDoc(docNum)) cout << "Successful" << endl; else cout << "Failed" << endl; } } } return 0; }
0.0分
0 人评分
C语言训练-数字母 (C语言代码)浏览:582 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:424 |
【简单计算】 (C语言代码)浏览:622 |
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:609 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:466 |
愚蠢的摄影师 (C++代码)浏览:934 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:653 |
C二级辅导-等差数列 (C语言代码)浏览:694 |
DNA (C语言代码)浏览:735 |
第三届阿里中间件性能挑战赛-总决赛亚军比赛攻略浏览:1145 |