Comment detail

LL Golf Hole 5 - 最上位の桁を数え上げる (Nested Flatten)

ちょっと不格好かなぁ…。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

void count(int n)
{
    int d = 1;
    int i = 0;
    while(i <= n)
    {
        std::cout << i << std::endl;
        i += d;
        if((i / (d * 10) > 0))
        {
            d *= 10;
        }
    }
}

int main(int, char* [])
{
    count(300);

    return 0;
}
mattsanさんの#7145を参考に標準入力に対応しつつgolf化.
164bytes. 改行5,空白4省略可で実質155bytes
本当はoperator<()を定義してcout<cin とかやりたかったけど、短さを優先しました。
1
2
3
4
5
6
7
#include<iostream>
using namespace std;
void f(ostream&o,istream&i){
  int c=0,d=1,n;i>>n;
  while(c<=n)o<<c<<"\n"&&(c+=d)&&c/d/10&&(d*=10);
}
main(){f(cout,cin);}
別関数に分けずにベタでmain内に書いたほうがよっぽど短かった orz
というわけで元コードは自分で-1.
116btyes.実質109bytes
1
2
3
4
5
#include<iostream>
main(){
  int c=0,d=1,n;std::cin>>n;
  while(c<=n)std::cout<<c<<"\n"&&(c+=d)&&c/d/10&&(d*=10);
}

Index

Feed

Other

Link

Pathtraq

loading...