青海省网站建设_网站建设公司_支付系统_seo优化
2025/12/24 16:24:19 网站建设 项目流程

2025年兰州大学计算机考研复试机试真题

2025年兰州大学计算机考研复试上机真题

历年兰州大学计算机考研复试上机真题

历年兰州大学计算机考研复试机试真题

更多学校题目开源地址:https://gitcode.com/verticallimit1/noobdream

N 诺 DreamJudge 题库:输入 “学校名称” 即可筛选该校历年机试真题,题目均在考纲范围内,按难度自动排序。还可搭配《计算机考研机试攻略》刷题,书中题目可通过题号直接在题库中查找。

字符分类

题目描述

Time Limit: 1000 ms
Memory Limit: 256 mb

从键盘上输入一个字符串,将该字符串分为数字、字母、其他字符三个部分输出。

例如:

输入:Thdad29#@12aH;77

输出:

ThdadaH

291277

#@;

输入输出格式
输入描述:

输入一串字符串,长度不超过100。

输出描述:

按题意输出。

输入输出样例
输入样例#:
Thdad29#@12aH;77
输出样例#:
ThdadaH 291277 #@;

代码一

  1. #include<iostream>
  2. using namespace std;
  3. int main() {
  4. string s;
  5. cin>>s;
  6. char ch;
  7. for(int i=0;i<s.length();i++) {
  8. ch = s[i];
  9. if((ch>='A'&&ch<='Z')||(ch>='a'&&ch<='z')) {
  10. cout<<ch;
  11. }
  12. }
  13. cout<<endl;
  14. for(int i=0;i<s.length();i++) {
  15. ch = s[i];
  16. if((ch>='0'&&ch<='9')) {
  17. cout<<ch;
  18. }
  19. }
  20. cout<<endl;
  21. for(int i=0;i<s.length();i++) {
  22. ch = s[i];
  23. if((ch<'A'||ch>'Z')&&(ch>'z'||ch<'a')&&(ch<'0'||ch>'9')) {
  24. cout<<ch;
  25. }
  26. }
  27. return 0;
  28. }

代码二

  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4. string str;cin>>str;
  5. string num,charact,other;
  6. for(int i = 0; i < str.size(); i++){
  7. if(str[i] >= 'a' && str[i] <= 'z' || str[i] >= 'A' && str[i] <= 'Z') charact+=str[i];
  8. else if(str[i] >= '0' && str[i] <= '9' ) num += str[i];
  9. else other += str[i];
  10. }
  11. cout<<charact<<endl<<num<<endl<<other<<endl;
  12. return 0;
  13. }

代码三

  1. #include<stdio.h>
  2. #include<string.h>
  3. int main(){
  4. char a[100];
  5. char b[100];
  6. char c[100];
  7. char d[100];
  8. scanf("%s",a);
  9. int sum=strlen(a);
  10. int q=0;
  11. int w=0;
  12. int e=0;
  13. for(int i=0;i<sum;i++){
  14. if(a[i]>='A' && a[i]<='z'){
  15. b[q]=a[i];
  16. q++;
  17. }
  18. else if(a[i]>='0' && a[i]<='9'){
  19. c[w]=a[i];
  20. w++;
  21. }
  22. else{
  23. d[e]=a[i];
  24. e++;
  25. }
  26. }
  27. printf("%s\n",b);
  28. printf("%s\n",c);
  29. printf("%s\n",d);
  30. return 0;
  31. }

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询