menu Secto白帽博客-专注于技术研究
C/C++基础算法练习-开门关门
860 浏览 | 2020-03-15 | 分类:C/C++,程序设计 | 标签:C/C++,程序设计,C,算法,C++,题解

宾馆有100个房间,从1——100编了号,第一个服务员把所有的房间门打开,第二个服务员把所有编号是2的倍数的房间作“相反处理”,第三个服务员把所有编号是3的倍数的房间作“相反处理”,……,以后每个服务员都是如此。当第100个服务员来过后,哪几扇门是开着的?输出这几扇门的编号。(所谓“相反处理”是:原来开着的门关上,原来关上的门打开。

#include <iostream>
using namespace std;
int main(){
    bool a[105]={0};
    for(int i=1;i<=100;i++){
        for(int j=i;j<=100;j++){
            if(j%i==0){
                if(a[j]==0) a[j]=1;
                    else a[j]=0;
            }
        }
    }
    for(int i=1;i<=100;i++){
        if(a[i]==1) cout<<i<<" ";
    }
    return 0;
}

By:海螺HL
Time:2020/3/15

知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议

发表评论

email
web

全部评论 (暂无评论)

info 还没有任何评论,你来说两句呐!

Emoji

Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /www/wwwroot/www.sectoer.cn/usr/themes/Cuckoo/includes/owo.php on line 46

Warning: file_get_contents(): Failed to enable crypto in /www/wwwroot/www.sectoer.cn/usr/themes/Cuckoo/includes/owo.php on line 46

Warning: file_get_contents(https://...@1.0.2/assets/json/owo.json): failed to open stream: operation failed in /www/wwwroot/www.sectoer.cn/usr/themes/Cuckoo/includes/owo.php on line 46

Warning: array_keys() expects parameter 1 to be array, null given in /www/wwwroot/www.sectoer.cn/usr/themes/Cuckoo/includes/owo.php on line 48

Warning: count(): Parameter must be an array or an object that implements Countable in /www/wwwroot/www.sectoer.cn/usr/themes/Cuckoo/includes/owo.php on line 49

Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /www/wwwroot/www.sectoer.cn/usr/themes/Cuckoo/includes/owo.php on line 87

Warning: file_get_contents(): Failed to enable crypto in /www/wwwroot/www.sectoer.cn/usr/themes/Cuckoo/includes/owo.php on line 87

Warning: file_get_contents(https://...@1.0.2/assets/json/owo.json): failed to open stream: operation failed in /www/wwwroot/www.sectoer.cn/usr/themes/Cuckoo/includes/owo.php on line 87

Warning: array_keys() expects parameter 1 to be array, null given in /www/wwwroot/www.sectoer.cn/usr/themes/Cuckoo/includes/owo.php on line 89

Warning: count(): Parameter must be an array or an object that implements Countable in /www/wwwroot/www.sectoer.cn/usr/themes/Cuckoo/includes/owo.php on line 90