竞赛
考级
#include<iostream> using namespace std;int main(){char c;cin>>c;if(c>='A'&&c<='Z'){cout<<c-64;}else{cout<<c-96;}}
A370.第几个字母
超简单,一遍过!!!
理论上来说,不使用26个分支是对手指和空间复杂度和时间复杂度友好的选择。 当然我不反对以上方法。 至少我使用的是以下方法。 「???」
'a'的ASCLL数值是97,'A'的ASCLL数值是65,'z'的ASCLL数值是122,'Z'的ASCLL数值是90。 不懂的看表: ASCLL -> A 65 Z 90 a 97 z 122 接着判断大小写,大写-64,小写-96 最后转整形,用int(a); 代码:
此题不用26个判断条件,只需用这几行代码就足以! 首先我们来看这两行代码: 先定义一个字符变量,再输入它,再看两个判断的条件: 如果这个字符是大写的那就执行else条件,如果不,那就执行条件。 你听懂了吗?关注贺子言!
#include<bits/stdc++.h>//submitRecord// using namespace std; //const int N=1e7+10; int main(){ //freopen("","r",stdin); //freopen("","w",stdout); ios::sync_with_stdio(); cin.tie(nullptr); cout.tie(nullptr); char a; cin>>a; if(a>=97){ cout<<int(a-('a'-1)); } else{ cout<<int(a-('A'-1)); } //fclose(stdin); //fclose(stdout); return 0; }
直接去转int,大写就-64,小写就-96
提交答案之后,这里将显示提交结果~