1. 程式人生 > 其它 >CF151B Phone Numbers 題解

CF151B Phone Numbers 題解

CF151B Phone Numbers 題解

Content

在一座城市中,每個人的電話號碼都是由六位整陣列成的,例如 11-45-14。

現在有 \(n\) 個人,第 \(i\) 個人有 \(s_i\) 個人的電話號碼。已知:

  • 計程車司機的電話號碼由六個相同的數字構成(如 66-66-66)。
  • 披薩外賣的電話號碼由六個遞減的數字構成(如 65-43-21)。
  • 其他的電話號碼都是女生的。

現在給出這 \(n\) 個人所擁有的電話號碼。眾所周知,找一個擁有某種事情相關的人的電話號碼最多的人辦這件事總會很靠譜。你需要求出你在辦某件事的時候應該找哪些人。

資料範圍:\(1\leqslant n\leqslant 100\)\(0\leqslant s_i\leqslant 100\)

Solution

這題是一道較為簡單的模擬題。

我們利用 scanf 的特性,按照格式輸入沒個電話號碼的六個數字,然後按照題目給出的規則將每個電話號碼歸入題目給出的型別中,同時統計每個人所擁有某種型別的電話號碼的數量。

統計完以後,分別按照擁有某種型別的電話號碼的數量降序排列,然後找出擁有和最多數量相同的人,最後再按照輸入順序輸出即可。

Code

int n, num[107], cnt;
struct node {
	string name;
	int x[107][7], taxi, pizza, girl, id;
}a[107], ans1[107], ans2[107], ans3[107];

ib cmp1(const node& tmp1, const node& tmp2) {return tmp1.taxi > tmp2.taxi;}
ib cmp2(const node& tmp1, const node& tmp2) {return tmp1.pizza > tmp2.pizza;}
ib cmp3(const node& tmp1, const node& tmp2) {return tmp1.girl > tmp2.girl;}
ib cmpid(const node& tmp1, const node& tmp2) {return tmp1.id < tmp2.id;}

int main() {
	n = Rint;
	F(i, 1, n) {
		num[i] = Rint, a[i].id = i; cin >> a[i].name;
		F(j, 1, num[i]) scanf("%1d%1d-%1d%1d-%1d%1d", &a[i].x[j][1], &a[i].x[j][2], &a[i].x[j][3], &a[i].x[j][4], &a[i].x[j][5], &a[i].x[j][6]);
	}
	F(i, 1, n) {
		F(j, 1, num[i]) {
			int fl1 = 1, fl2 = 1;
			F(k, 1, 6) if(a[i].x[j][k] != a[i].x[j][1]) {fl1 = 0; break;}
			F(k, 2, 6) if(a[i].x[j][k] >= a[i].x[j][k - 1]) {fl2 = 0; break;}
			if(fl1) a[i].taxi++;
			else if(fl2) a[i].pizza++;
			else a[i].girl++;
		}
	}
	sort(a + 1, a + n + 1, cmp1);
	int tmp = a[1].taxi;
	sort(a + 1, a + n + 1, cmpid);
	printf("If you want to call a taxi, you should call: ");
	F(i, 1, n) if(a[i].taxi == tmp) ans1[++cnt] = a[i];
	F(i, 1, cnt) cout << ans1[i].name << (i == cnt ? ".\n" : ", ");
	sort(a + 1, a + n + 1, cmp2);
	printf("If you want to order a pizza, you should call: ");
	tmp = a[1].pizza, cnt = 0;
	sort(a + 1, a + n + 1, cmpid);
	F(i, 1, n) if(a[i].pizza == tmp) ans2[++cnt] = a[i];
	F(i, 1, cnt) cout << ans2[i].name << (i == cnt ? ".\n" : ", ");
	sort(a + 1, a + n + 1, cmp3);
	printf("If you want to go to a cafe with a wonderful girl, you should call: ");
	tmp = a[1].girl, cnt = 0;
	sort(a + 1, a + n + 1, cmpid);
	F(i, 1, n) if(a[i].girl == tmp) ans3[++cnt] = a[i];
	F(i, 1, cnt) cout << ans3[i].name << (i == cnt ? ".\n" : ", ");
	return 0;
}