From b06a16ab477eb12218e303fc4a213860e28d1a3d Mon Sep 17 00:00:00 2001 From: kate_tw Date: Wed, 27 Apr 2022 21:28:21 +0800 Subject: [PATCH] =?UTF-8?q?850349=20316=2013=20=E5=BC=B5=E5=8F=88=E9=A6=A8?= =?UTF-8?q?=20=E5=9F=BA=E7=A4=8E=E7=8F=AD=E4=BD=9C=E6=A5=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 850349/The Supermarket Queue.cpp | 47 ++++++++++++++++++++++++++++++++ 850349/odd.cpp | 37 +++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 850349/The Supermarket Queue.cpp create mode 100644 850349/odd.cpp diff --git a/850349/The Supermarket Queue.cpp b/850349/The Supermarket Queue.cpp new file mode 100644 index 0000000..086075c --- /dev/null +++ b/850349/The Supermarket Queue.cpp @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include +using namespace std; +int queueTime(vector,int); + +int main() { + vector customers; + int num; + int y = 1; + while(true){ + if(y != 0){ + cin >> y; + customers.push_back(y); + }else{ + cin >> num; + cout << queueTime(customers, num); + break; + } + } +} +int queueTime(vector time, int num){ + queue fin; + for(int i = 0; i < time.size(); i++){ + fin.push(i); + } + + vector n; + for(int j = 0; j < num; j++){ + n[j] = fin.front(); + fin.pop(); + } + for(int g = 0; g < fin.size(); g++){ + for(int k = 0; k < fin.size(); k++){ + sort(n.begin(), n.end()); + n.begin() += fin.front(); + fin.pop(); + } + } + int ans = 0; + for(int h = 0; h < n.size(); h++){ + ans = n[h]; + } + return ans; +} \ No newline at end of file diff --git a/850349/odd.cpp b/850349/odd.cpp new file mode 100644 index 0000000..f736eb1 --- /dev/null +++ b/850349/odd.cpp @@ -0,0 +1,37 @@ +#include +#include +using namespace std; +int odd(vector ); +int n = 0, ans = 0; +int numbers = 0; + +int main() { + vector num; + cout << "輸入一個整數串列(輸入0停止)\n"; + while(true){ + + cin >> numbers; + if(numbers != 0){ + num.push_back(numbers); + }else{ + cout << "答 : "; + cout << odd(num) << "\n"; + break; + } + } +} + +int odd(vector num){ + for(int i = 0; i < num.size(); i++){ + n = 0; + for(int k = 0; k < num.size(); k++){ + if(num[i] == num[k]){ + n += 1; + } + } + if(n % 2 != 0){ + ans = num[i]; + } + } + return ans; +} \ No newline at end of file