题意:给你年份,输出这一年的第256天的年月日,两种日历计算方法,注意区分
#include <bits/stdc++.h>using namespace std;int Mouth(int y,int m) { if(m == 1 || m== 3 || m==5 || m== 7 || m==8||m==10||m==12) return 31; else if( m == 2) { if(y < 1918) { if(y%4 ==0) return 29; else return 28; } if(y%400==0|| (y %4 ==0 && y %100!=0)) return 29; else return 28; } return 30;}int main(){ int y; scanf("%d",&y); int ant = 256; if(y == 1918) { ant -= 46; for(int i = 3;i<=12;i++) { if(ant <=Mouth(y,i)) { printf("%02d.%02d.%d",ant,i,y); break; } else ant -= Mouth(y,i); } } else { for(int i = 1;i<=12;i++) { if(ant <=Mouth(y,i)) { printf("%02d.%02d.%d",ant,i,y); break; } else ant -= Mouth(y,i); } } return 0;}题意:给你一些数,排序,数字比较大,字符串处理
#include <bits/stdc++.h>using namespace std;const int maxn = 1e6+100;;vector<string> num[maxn];int main(){ std::ios::sync_with_stdio(false); int n; cin >> n; string data; int End = 0; for(int i = 0 ;i<n;i++) { cin>>data; num[data.size()].push_back(data); int len = data.size(); End = max(End,len); } for(int i = 1;i<=End;i++) { if(num[i].size()) { sort(num[i].begin(),num[i].end()); for(int j = 0;j<num[i].size();j++) cout<<num[i][j]<<endl; } } return 0;}题意:给你一个矩阵,问所给圆和正方形共同覆盖的点。判断点是不是在圆中和是不是在多边形中。模板题
#include <bits/stdc++.h>using namespace std;const double eps = 1e-9;struct Point{ double x,y; Point() {} Point(double _x,double _y):x(_x),y(_y) {} Point Operator + (const Point p) const{ return Point(p.x+x,p.y+y); } Point operator / (const double p) const{ return Point(x/p,y/p); } Point operator - (const Point p) const{ return Point(x-p.x,y-p.y); }} square[5];int _sign(double x){ return x>eps?1:(x<-eps?2:0);}double xmult(Point p1, Point p2, Point p){ return (p1.x - p.x) * (p2.y - p.y) - (p2.x - p.x)*(p1.y - p.y);}int IsPointSquare(Point p){ int s[3] = {1,1,1}; for(int i = 0; i < 4 && s[1]|s[2]; i++){ s[_sign(xmult(square[(i+1)%4], p, square[i]))] = 0; } return s[1]|s[2] ;}Point Rotate(Point p,int op){ return Point(-p.y * op, p.x * op);}double xcir,ycir,r;bool IsPointCircle(Point p){ return (xcir - p.x)*(xcir - p.x)+(ycir - p.y) * (ycir - p.y) <= r * r;}bool IsPointShape(Point p){ if(IsPointCircle(p) || IsPointSquare(p)) return true; return false;}int w,h;bool vis[110][110];int main(){ scanf("%d %d",&h,&w); scanf("%lf %lf %lf",&ycir, &xcir, &r); scanf("%lf %lf %lf %lf",&square[0].y, &square[0].x, &square[2].y, &square[2].x); Point center = (square[0] + square[2])/2; square[1] = Rotate(square[2] - center,-1) + center; square[3] = Rotate(square[2] - center, 1) + center; for(int i = 0; i < w; i++){ for(int j = 0; j < h; j++){ vis[i][j] = IsPointShape(Point(i,j)); } } for(int i = 0; i < w; i++) { for(int j = 0; j < h; j++) { if(vis[i][j]) printf("#"); else printf("."); } printf("/n"); } return 0;}题意:给你一个区间,问区间中数是素数并且每一位也是素数。小于10的素数只有2,3,5,7。由于
新闻热点
疑难解答