• 计算机模拟试题


    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <iostream>
    
    using namespace std;
    
    // 第一题 
    int li(int n) {
    	return n*n*n;
    }
    void problem1() {
    	for(int i = 1; i <= 9; ++i) {//百位数  
    		int num = i*100;
    		for(int j = 0; j <= 9; ++j) 
    			for(int k = 0; k <= 9; ++k)
    				if(num+(j*10)+k == li(i)+li(j)+li(k))
    					printf("%d
    ", num+(j*10)+k);
    	} 
    }
    //第二题
    bool isPrime(int n) { // 是素数返回1 
    	for(int i = 2; i <= n/2; ++i)
    		if( !(n%i) ) return 0;
    	return 1;
    }
    void problem2() {
    	for(int i = 2; i <= 200; ++i)
    		if(isPrime(i))
    			printf("%d ",i);
    	printf("
    ");	
    } 
    // 第三题
    void problem3() {
    	char a[] = "CddBb456!*e2";
    	int DaX = 0; // 大写字母
    	int XiX = 0; // 小写字母
    	int ShZ = 0; // 数字
    	int QiT = 0; //其他字符;
    	for(int i = 0; i < strlen(a); ++i)
    		if('A' <= a[i] && a[i] <= 'Z') DaX++;
    		else if('a' <= a[i] && a[i] <= 'z') XiX++;
    		else if('0' <= a[i] && a[i] <= '9') ShZ++;
    		else QiT++; 
    	printf("大写:%d, 小写:%d 数字:%d 其他:%d
    ",DaX,XiX,ShZ,QiT);	
    }
    // 第四题
    struct Table {
    	int val;
    	Table *nxt;
    };
    Table *Head;
    int length;
    void create() {
    	Table *p = Head;
    	int val;
    	while(scanf("%d", &val) != EOF) {
    		p->val = val;
    		p = p->nxt;
    		++length;
    	}
    }
    void Sort() {
    	for(Table* i = Head; i != NULL; i = i->nxt)
    		for(Table* j = i; j->nxt != NULL; j = j->nxt)
    			if(j->val > j->nxt->val) {
    				swap(j->val, j->nxt->val);	
    				swap(j->nxt, j->nxt->nxt);
    			}
    	for(Table* i = Head; i != NULL; i = i->nxt)
    		printf("%d ", i->val);
    	for(Table* i = Head; i != NULL; i = i->nxt)
    		for(Table* j = i; j->nxt != NULL; j = j->nxt)
    			if(j->val < j->nxt->val) {
    				swap(j->val, j->nxt->val);	
    				swap(j->nxt, j->nxt->nxt);
    			}		
    	for(Table* i = Head; i != NULL; i = i->nxt)
    		printf("%d ", i->val);
    }
    void problem4() {
    	create();
    	Sort();
    } 
    int main() {
    	problem1();
    	problem2();
    	problem3();
    	problem4();
    	return 0;
    } 
    
  • 相关阅读:
    CentOS7安装redis
    apache修改最大连接数报错
    阿里云服务器安全组设置
    CentOS7为firewalld添加开放端口
    php程序报错:PHP Core Warning/cannot open shared object file: No such file or directory
    centos7配置Apache支持HTTPS
    linux系统下Apache日志分割(按天生成文件)
    springboot 项目依赖 es包版本异常
    jboss Marshalling, 服务端收不到消息
    gateway 整合 websocket demo
  • 原文地址:https://www.cnblogs.com/tply/p/14148526.html
Copyright © 2020-2023  润新知