啦啦啦在课上写代码就是爽,效率特别快!
感觉在动手码之前不如简单的拿笔写一下思路,这样思路会很清晰,写起来也不会那么的费劲了。
代码如下:
#include<stdio.h>
int n;
const int N = 500;
struct st{
int a, b, c;
bool is_sleep = (c > a) ? true : false;//现在状态
};
//是否去睡觉
bool goto_sleep(int m) {
st sta[N];
int num = 0;
for (int i = 0; i < n; i++) {
if (i != m && sta[i].is_sleep) num++;
}
if (num > n - num) return true;
else return false;
}
//更改学生状态
void next_minute() {
st sta[N];
for (int i = 0; i < n; i++) {
sta[i].is_sleep = goto_sleep(i);
}
}
int main() {
st sta[N];
while (scanf_s("%d", &n) && n != 1) {
for (int i = 0; i < n; i++) {
scanf_s("(%d,%d,%d)", sta[i].a, sta[i].b, sta[i].c);
}
//每分钟检查有没有全部清醒的时刻
for (int time = 0; time < N; time++) {
for (int i = 0; i < n; i++) {
if (sta[i].is_sleep == true) {
next_minute();
break;
}
}
printf("the time is %d", time);
return 0;
}
printf("-1");
return 0;
}
}