Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

#C - (削除) 95 (削除ここまで) 83 characters

C - (削除) 95 (削除ここまで) 83 characters

main(n,k){scanf("%d",&n);k=(n+9)%10;printf("%d%s\n",n,k<3?"st0円nd0円rd"+3*k:"th");}

Degolfed:

main(n,k)
{
 scanf("%d",&n);
 k=(n+9)%10; // xx1->0, xx2->1, xx3->2
 printf("%d%s\n",n,k<3?"st0円nd0円rd"+3*k:"th");
}

We could do k=(n-1)%10 instead of adding 9, but for n=0 we would get an incorrect behaviour, because in C (-1)%10 evaluates to -1, not 9.

#C - (削除) 95 (削除ここまで) 83 characters

main(n,k){scanf("%d",&n);k=(n+9)%10;printf("%d%s\n",n,k<3?"st0円nd0円rd"+3*k:"th");}

Degolfed:

main(n,k)
{
 scanf("%d",&n);
 k=(n+9)%10; // xx1->0, xx2->1, xx3->2
 printf("%d%s\n",n,k<3?"st0円nd0円rd"+3*k:"th");
}

We could do k=(n-1)%10 instead of adding 9, but for n=0 we would get an incorrect behaviour, because in C (-1)%10 evaluates to -1, not 9.

C - (削除) 95 (削除ここまで) 83 characters

main(n,k){scanf("%d",&n);k=(n+9)%10;printf("%d%s\n",n,k<3?"st0円nd0円rd"+3*k:"th");}

Degolfed:

main(n,k)
{
 scanf("%d",&n);
 k=(n+9)%10; // xx1->0, xx2->1, xx3->2
 printf("%d%s\n",n,k<3?"st0円nd0円rd"+3*k:"th");
}

We could do k=(n-1)%10 instead of adding 9, but for n=0 we would get an incorrect behaviour, because in C (-1)%10 evaluates to -1, not 9.

Source Link

#C - (削除) 95 (削除ここまで) 83 characters

main(n,k){scanf("%d",&n);k=(n+9)%10;printf("%d%s\n",n,k<3?"st0円nd0円rd"+3*k:"th");}

Degolfed:

main(n,k)
{
 scanf("%d",&n);
 k=(n+9)%10; // xx1->0, xx2->1, xx3->2
 printf("%d%s\n",n,k<3?"st0円nd0円rd"+3*k:"th");
}

We could do k=(n-1)%10 instead of adding 9, but for n=0 we would get an incorrect behaviour, because in C (-1)%10 evaluates to -1, not 9.

AltStyle によって変換されたページ (->オリジナル) /