BestCoder Round #21 A

本文介绍了一个简单的算法,用于确定在第n天需要复习哪些天学习过的单词。通过与预设的复习周期(1, 2, 4, 7, 15天)进行比较,该算法能够有效地输出所有需要复习的日期。

题目大意:输入n,然后输出在这一天改复习那几天学过的单词。

算法思想:

分别用 n与1,2,4,7,15做差,然后输出大于零的差即可,不过要注意最后一个差后要换行而不是空格。

代码如下:

#include <iostream>  
#include <cstring>  
using namespace std;   
int main(){  
         int n;  
        while(cin>>n){  
           int count=0;   
           if(n-15>0){
               if(count==0)
                   cout<<n-15;
               else 
                   cout<<" "<<n-15;     
               count++;  
           }  
           if(n-7>0){   
               if(count==0)
                   cout<<n-7;
               else 
                   cout<<" "<<n-7;     
               count++;   
           }  
           if(n-4>0){    
                if(count==0)
                   cout<<n-4;
               else 
                   cout<<" "<<n-4;     
               count++;  
           }  
           if(n-2>0){    
               if(count==0)
                   cout<<n-2;
               else 
                   cout<<" "<<n-2;     
               count++;    
           }  
           if(n-1>0){  
                if(count==0)
                   cout<<n-1;
               else 
                   cout<<" "<<n-1;     
               count++;     
           } 
          cout<<endl; 
        }
        return 0;  
    }  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值