蓝桥杯十天备战day1-模拟基础 1.注意ios::sync_with_stdio(0);//开同步流节约时间 cin.tie(0); cout.tie(0); int x, y; int n; while (cin n) {//0为输入结束标志 if (n 0) break; } while (cin n)//无输入结束标志 { } //注意cin和scanf无法读入空格 //gets有经典漏洞 //使用getline直接读一行 string str; getline(cin, str); //注意cin读入时会剩一个换行符 // getline把换行符读入进来会直接导致结束字符串读入 //字符串与数字的相互转换 int x stoi(str);//只能返回int类型 string t to_string(x);2.日期问题模板for (int year 2000;year 2022;year) {//从需要的年份范围开始枚举 for (int month 1;month 12;month) { for (int day 1;day 31;day) { if (month 1 || month 3 || month 5 || month 7 || month 8 || month 10 || month 12); else if (month 2) { if ((year % 4 0 year % 100 ! 0) || year % 400 0) { if (day 29) break; } else { if (day 28) break; } } else { if (day 30) break; } //统计天数的话记得在前面提前定义计数变量 } } }字典序排序可以开string数组用sort函数struct里的成员默认为publicclass里的成员默认为private先写暴力再写正确代码学习生成随机数对拍3.注意double比较时精度丢失的问题abs求整数的绝对值fabs求浮点数的绝对值4.蓝桥杯真题double精度题目详情 - 01 串的熵(结果填空) - DashOJ#includebits/stdc.h using namespace std; int main() { int n 23333333; for (int i 1;i (n/2);i) { double ai*1.0/n; double b(n-i)*1.0/n; double s 0; s - i * a * log2(a) (n - i) * b * log2(b); if (fabs(s - 11625907.5798) ( 1e-4))//如果写1e-6要求精度太高反而无法输出 { cout i endl; break; } } return 0; }https://dashoj.com/p/66#include bits/stdc.h using namespace std; int a[10006]; int tt[10006],xm[10006]; double t0,x0; int n; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cinn; for(int i1;in;i) { cina[i]; } for(int i1;in;i) { cintt[i]; ta[i]*1.0*tt[i]/100; } for(int i1;in;i) { cinxm[i]; xa[i]*1.0*xm[i]/100; } if(fabs(t-x)1e-4) { coutsameendl; } else if(tx) { coutkeendl; } else if(tx) { coutdoendl; } return 0; }