Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

850349 316 13 張又馨 基礎班作業 #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions 850349/The Supermarket Queue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <stack>
using namespace std;
int queueTime(vector<int>,int);

int main() {
vector <int> 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<int> time, int num){
queue <int> fin;
for(int i = 0; i < time.size(); i++){
fin.push(i);
}

vector <int> 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;
}
37 changes: 37 additions & 0 deletions 850349/odd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <iostream>
#include <vector>
using namespace std;
int odd(vector <int>);
int n = 0, ans = 0;
int numbers = 0;

int main() {
vector <int> 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 <int> 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;
}