CCF 20191201 报数

  • 思路:for循环j计总共报出的数,i计算从开始报数,数的变化情况,由于跳过的数,不在j的计算范围之内,i != j.
    1. i % 7 == 0跳过报数
    2. i含有7,将i转成字符串,后用find('7') != -1 跳过报数
#include<iostream>
#include<sstream>
#include<string>

using namespace std;

int ans[4] = {0};
int main(){
    int n;
    cin>>n;
    stringstream ss;
    for(int i = 1,j = 0; j < n; i++,j++){
        string s;
        ss.clear();
        ss.str("");
        ss<<i;
        ss>>s;
        if(s.find('7') != -1 || i % 7 == 0){
//            cout<<i<<endl;
            j--;
            if(i % 4 == 0){
                ans[3]++;
            }
            else if(i % 4 == 1){
                ans[0]++;
            }
            else if(i % 4 == 2){
                ans[1]++;
            }
            else if(i % 4 == 3){
                ans[2]++;
            }
        }
    }
    for(int i = 0; i < 4; i++){
        cout<<ans[i]<<endl;
    }

	return 0;
}

猜你喜欢

转载自www.cnblogs.com/blink-cz/p/12639985.html
今日推荐