Open Nutcha0751 opened 6 months ago
using namespace std;
int ids[] = {99, 12, 48, 105, 10, 15, 25, 46, 499, 128, 87, 52, 221, 300, 714, 188, 189, 910, 412, 555}; char genders[] = {'m', 'f', 'm', 'm', 'f', 'f', 'f', 'm', 'm', 'f', 'm', 'f', 'f', 'm', 'f', 'f', 'f', 'm', 'm', 'f'}; string faculty[] = {"eng", "med", "econ", "med", "eng", "law", "law", "dent", "med", "camt", "med", "dent", "econ", "eng", "med", "eng", "eng", "econ", "econ", "agri"}; int N = sizeof(ids) / sizeof(ids[0]);
int main() { cout << "Input gender and faculty to search:\n"; char gen; string fac; int count = 0; cin >> gen >> fac;
for (int i = 0; i < N; i++)
{
if (gen == genders[i] && fac == faculty[i])
{
cout << "Student " << count + 1 << ": " << ids[i] << endl;
count++;
}
}
if(count == 0) cout << "not found" << endl;
return 0;
}
using namespace std;
void sort3ints(int a, int b, int c) { int high = max(max(a, b), c); int low = min(min(a, b), c); int med = min(min(max(a, b), max(b, c)), max(a, *c));
*a = high;
*b = med;
*c = low;
}
int main() { int x = 8, y = 92, z = 33; sort3ints(&x, &y, &z); cout << x << endl; cout << y << endl; cout << z << endl; }
using namespace std;
void sort3ints(int a, int b, int c)
{
vector
int main() { int x = 8, y = 92, z = 33; sort3ints(&x, &y, &z); cout << x << endl; cout << y << endl; cout << z << endl; }
using namespace std;
void sort3ints(int a, int b, int c)
{
priority_queue
*a = num.top();
num.pop();
*b = num.top();
num.pop();
*c = num.top();
num.pop();
}
int main() { int x = 8, y = 92, z = 33; sort3ints(&x, &y, &z); cout << x << endl; cout << y << endl; cout << z << endl; }
ไผ่จำได้ลางๆ
void String2Upper(std::string & str){ for(unsigned i = 0; i < str.size(); i++){ str[i] = toupper(str[i]); } }
std::string faceValue[] = {"SPADE", "HEART", "DIAMOND", "CLUB"}; std::string suitValue[] ={"2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3"};
int GetFaceValue(std::string face){ for(unsigned i = 0; i < 4; i++){ if(face == faceValue[i]) return i; } return -1; }
int GetSuitValue(std::string suit){ for(unsigned i = 0; i < 13; i++){ if(suit == suitValue[i]) return i; } return -1; }
class Card{ public: std::string face; std::string suit; Card(std::string code){ int splitter = code.find(" "); suit = code.substr(0, splitter); face = code.substr(splitter + 1); String2Upper(suit); String2Upper(face); }
bool operator>(const Card& x){
if(suit == x.suit){
return GetFaceValue(face) < GetFaceValue(x.face);
}else return GetSuitValue(suit) < GetSuitValue(x.suit);
}
};
Card strongestCard(std::vector
int main(){
std::vector
Card a = Card("7 Diamond");
Card b = Card("A Spade");
Card z = Card("2 CLUB");
Card w = Card("2 SpaDe");
hand.push_back(a);
hand.push_back(b);
hand.push_back(z);
hand.push_back(w);
std::cout << strongestCard(hand).suit << " " << strongestCard(hand).face;
}
ข้อ 1
แพมทำ แต่ไม่ถูกทุกกรณี
include
include
using namespace std;
int ids[] = {99,12,48,105,10,15,25,46,499,128,87,52,221,300,714,188,189,910,412,555}; char genders[] = {'m','f','m','m','f','f','f','m','m','f','m','f','f','m','f','f','f','m','m','f'}; string faculty[] = {"eng","med","econ","med","eng","law","law","dent","med","camt","med","dent","econ","eng","med","eng","eng","econ","econ","agri"}; int N = sizeof(ids)/sizeof(ids[0]);
int main(){ cout << "Input gender and faculty to search:\n"; char gen; string fac; int count = 0; cin >> gen >> fac;
}
ข้อ 2
จงเขียน Function ชื่อ sort3ints ให้สอดคล้องกับตัวอย่างการใช้งานด้านล่างนี้ ซึ่งจากตัวอย่างการใช้งานจะเห็นได้ว่า sort3ints() จะมีการรับ Input 3 ตัว และไม่มีการ Return ค่าใด ๆ โดยเมื่อเรียกใช้งาน sort3ints() กับตัวแปร a, b, c ตามในตัวอย่าง จะเห็นได้ว่า ค่าที่ถูกเก็บไว้ในตัวแปรทั้ง 3 จะถูกสลับใหม่ โดยที่ค่าที่มากที่สุดจะมาอยู่ที่ตัวแปร a ค่าตรงกลางจะมาอยู่ที่ตัวแปร b และค่าที่น้อยที่สุดจะมาอยู่ที่ตัวแปร c