顺子日期
小明特别喜欢顺子。顺子指的就是连续的三个数字:123、456 等。顺子日期指的就是在日期的 yyyymmdd 表示法中,存在任意连续的三位数是一个顺子的日期。例如 20220123 就是一个顺子日期,因为它出现了一个顺子:123; 而 20221023 则不是一个顺子日期,它一个顺子也没有。小明想知道在整个 2022 年份中,一共有多少个顺子日期?
for循环里面的if条件不能分开写,因为会存在两个条件都满足的情况,这样就会多增加一次,导致答案
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long LL;
const int N = 200010;
int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
bool value(int month,int day){
if(month<1||month>12) return false;
if(day==0) return false;
if(day>days[month]) return false;
return true;
}
int main(){
int ans=0;
for(int i=0101;i<=1231;i++){
int b=i/100;
int c=i%100;
int d=i/1000%10;
int e=i/100%10;
int f=i/10%10;
int g=i%10;
if(value(b,c)&&((e==d+1&&f==e+1)||(f==e+1&&g==f+1))){
//cout<<i<<"\n";
ans++;
}
}
cout<<ans;
return 0;
}
字节换算
1TB=1024GB
1GB=1024MB
1MB=1024KB
1KB=1024字节
1字节=8位
256MB存多少个32位的字
res=256*1024*1024*8/32
年号字串
小明用字母 A 对应数字 11,B 对应 22,以此类推,用 Z 对应 2626。对于 2727 以上的数字,小明用两位或更长位的字符串来对应,例如 AA 对应 2727,AB 对应 2828,AZ 对应 5252,LQ 对应 329329。
请问 20192019 对应的字符串是什么?
模拟赛的时候还不会做这题,真的想哭,现在发现原来很简单,开心
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long LL;
const int N = 200010;
int main(){
char a[27];
int temp=64; //A的ascll码值是65,后面可以依次加
for(int i=1;i<=26;i++){
a[i]=(char)(temp+i); //a[1]=(char)65=A
}
int x=2019/26/26; //第一位
int y=2019/26%26; //第二位
int z=2019%26; //第三位
cout<<a[x]<<a[y]<<a[z];
return 0;
}