답안 #570999

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
570999 2022-06-01T02:06:51 Z AGE Trol (COCI19_trol) C++14
30 / 50
1 ms 212 KB
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define int unsigned long long
using namespace std;
const int N=1e6,M=2e3;

main(){

    int q;
    cin>>q;

    while(q--){

        int l,r;
        cin>>l>>r;

        int sum=l;

        while(sum>9){

            int x=sum;
            int y=0;
            while(x>0)
                y+=x%10,x/=10;

            sum=y;
        }


        int sum2=r;

        while(sum2>9){

            int x=sum2;
            int y=0;
            while(x>0)
                y+=x%10,x/=10;

            sum2=y;
        }

        double ans=0;
        for(int j=1;j<10;j++){

            int ok1=0,ok2=0;

            if((r-l+1)%9!=0){
            if(sum>sum2){
                if(j>=sum||j<=sum2)
                    ok1=1;
            }

            else{
                if(j>=sum&&j<=sum2)
                    ok1=1;
            }
            }
            ans+=(double)(ok1*j)+(int)((r-l+1)/9)*j;
        }

        cout<<ans<<endl;
    }

    return 0;

}


Compilation message

trol.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main(){
      | ^~~~
trol.cpp: In function 'int main()':
trol.cpp:47:23: warning: unused variable 'ok2' [-Wunused-variable]
   47 |             int ok1=0,ok2=0;
      |                       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Incorrect 1 ms 212 KB Output isn't correct