码迷,mamicode.com
首页 > 其他好文 > 详细

A 777 吉林大学ACM集训队选拔赛(重现赛)

时间:2020-06-13 19:43:32      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:调试   typedef   输出   coder   sizeof   turn   pow   test   ios   

https://ac.nowcoder.com/acm/contest/5944/A

 

太坑了,有空一定把它做出来

//真坑,就有一条,我加上输出调试的时候是对的,但是交的时候就变成了错的
#include <cmath>
#include <cstring>
#include <iostream>

using namespace std;

typedef long long ll;

ll t;

int main(){
    cin >> t;
    while (t -- ){
        ll n;
        ll a[10], b[10];
        
        cin >> n;
        
        memset(a, 0, sizeof 0);
        memset(b, 0, sizeof 0);
        //记录为每一个数的第i位后为0的数,如i = 2,n = 321, 则a[2] = 320;
        for (int i = 1; i <= 10; i ++ ){
            a[i] = n / pow(10, i - 1);
        }
        //记录输入的n是几位数
        int cnt = 0, t = n, m = n;
        while (t){
            t /= 10;
            cnt ++;
        }
        //记录每一位的数是几
        for (int i = 1; i <= m; i ++ ){
            b[i] = m % 10;
            m /= 10;
        }
        //求结果
        ll ans = 0;
        for (int i = cnt; i >= 1; i -- ){
            if (b[i] > 7) ans += ((a[i + 1] + 1) * pow(10, i - 1));
            else if (b[i] == 7){
                 ans += (a[i + 1] * pow(10, i - 1)) + (n - a[i] * pow(10, i - 1)) + 1;
                //cout << n << endl;
                //cout << a[i] << endl;
                //cout << pow(10, i - 1) << endl;
            }
            
            else ans += a[i + 1] * pow(10, i - 1);
            cout << ans << ‘ ‘ << a[i + 1] << ‘ ‘ << a[i] << ‘ ‘ << pow(10, i - 1) << endl;
        }
        
        cout << ans << endl;
    }
    
    return 0;
}

  

//
#include<iostream>
#include<math.h>
#include<string>
using namespace std;

int count7(int number, int d) {
	int pownum = pow(10, d);
	int gaowei = number / (pownum * 10);  
	int digit = (number / pownum) % 10;   
	if (digit < 7) {  
		return gaowei * pownum;
	}else if (digit == 7) {
		return gaowei * pownum + number % pownum + 1;
	}else {
		return (gaowei + 1) * pownum;
	}
}

int main() {
	int t;
	cin >> t;
	while (t -- ){
	    int number;
	cin >> number;
	int count = 0;
	string str;
	str = to_string(number);

	for (int i = 0; i < str.size(); i++) {
		count += count7(number, i);
	}
	cout << count<< endl;
	}
	return 0;
}

  

A 777 吉林大学ACM集训队选拔赛(重现赛)

标签:调试   typedef   输出   coder   sizeof   turn   pow   test   ios   

原文地址:https://www.cnblogs.com/Iamcookieandyou/p/13121186.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!