HJ1 字符串最后一个单词的长度
题目:https://www.nowcoder.com/practice/8c949ea5f36f422594b306a2300315da?tpId=37&tqId=21224&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=
1 #include<bits/stdc++.h> 2 using namespace std; 3 char s[5010]; 4 int main(){ 5 while(~scanf("%s",s)); 6 cout<<strlen(s); 7 return 0; 8 }
HJ2 计算某字符出现次数
题目:https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1?tpId=37&rp=1&ru=%2Fexam%2Foj%2Fta&qru=%2Fexam%2Foj%2Fta&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D37&difficulty=&judgeStatus=&tags=&title=&gioEnter=menu
不知道为啥,读整行不让我用gets,只能用cin.getline(s,1001)或者cin.get(s,1001)。getline和get的区别是getline读完之后不包括换行符,get会把换行符也弄进s里。
注意c可以对应大小写的情况。
1 #include<bits/stdc++.h> 2 using namespace std; 3 char c; 4 char s[1010]; 5 int main(){ 6 cin.getline(s,1001); 7 cin>>c; 8 int l=strlen(s),cnt=0,f=0; 9 if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))f=1; 10 for(int i=0;i<l;i++) 11 if(s[i]==c||(f&&abs(c-s[i])=='a'-'A')) cnt++; 12 cout<<cnt; 13 return 0; 14 }
HJ3 明明的随机数
题目:https://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0?tpId=37&tqId=21226&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=
一个很简单的桶排序
1 #include<bits/stdc++.h> 2 using namespace std; 3 bool f[510]; 4 int n,a; 5 int main(){ 6 cin>>n; 7 for(int i=1;i<=n;i++) { 8 scanf("%d",&a); 9 f[a]=1; 10 } 11 for(int i=1;i<=500;i++) 12 if(f[i])printf("%d\n",i); 13 return 0; 14 }
标签:HJ10,试题库,HJ01,int,cin,2Fexam%,ta,getline,2Foj% From: https://www.cnblogs.com/AlenaNuna/p/18400115