Hướng dẫn giải của Nhân 1


Chỉ dùng lời giải này khi không có ý tưởng, và đừng copy-paste code từ lời giải này. Hãy tôn trọng người ra đề và người viết lời giải.
Nộp một lời giải chính thức trước khi tự giải là một hành động có thể bị ban.

Lưu ý: Các code mẫu dưới đây chỉ mang tính tham khảo và có thể không AC được bài tập này

Code mẫu của flashmt

const d='1234567898765432';
      c2='123456790123456790';
      b2='098765432098765432';
      c='123456790';
      b='098765432';
      c1:array[1..9] of byte=(1,2,3,4,5,6,7,9,0);
      b1:array[1..9] of byte=(0,9,8,7,6,5,4,3,2);
var n,k,p,q,j,i,t:longint;

begin
     readln(k);
     for i:=1 to k do
     begin
          readln(n);
          p:=(n-1) div 9;
          q:=(n-1) mod 9;
          t:=p div 2;
          for j:=1 to t do write(c2);
          if p mod 2 = 1 then write(c);
          if q=8 then write(d)
          else
          begin
               for j:=1 to q do write(c1[j]);
               for j:=10-q to 9 do write(b1[j]);
          end;
          for j:=1 to t do write(b2);
          if p mod 2 = 1 then write(b);
          writeln(1);
     end;
end.

Code mẫu của happyboy99x

#include<cstdio>

int n; char res[2000000];

void testcase() {
    scanf("%d", &n);
    int memo = 0, p = n+n-2;
    for(int i = 1; i <= n; ++i, --p) {
        memo += i;
        res[p] = memo % 10 + 0x30;
        memo /= 10;
    }
    for(int i = n-1; i > 0; --i, --p) {
        memo += i;
        res[p] = memo % 10 + 0x30;
        memo /= 10;
    }
    if(memo) printf("%d", memo);
    res[n+n-1] = 0; printf("%s\n", res);
}

int main() {
    int tc; scanf("%d", &tc);
    while(tc--) testcase();
    return 0;
}

Code mẫu của ladpro98

var i,j,k,n,t:longint;
begin
        readln(t);
        for j:=1 to t do
          begin
                readln(n);
                for i:=1 to (n-1) div 9 do
                        write('123456790');
                k:=(n-1) mod 9;
                for i:=1 to k do
                        write(chr(48+i));
                for i:=k+1 downto 2 do
                        write(chr(48+i));
                for i:=1 to (n-1) div 9 do
                        write('098765432');
                writeln(1);
        end;
end.

Code mẫu của RR

const
  MAXN=2000111;
var
  a:array[1..2000111] of longint;
  mod10,div10:array[0..2000111] of longint;
  i,u,nho,n,test:longint;
begin
  for i:=1 to 2000000 do
    begin
      mod10[i]:=mod10[i-1]+1;
      if mod10[i]=10 then
        begin
          mod10[i]:=0;
          div10[i]:=div10[i-1]+1;
        end
      else
        div10[i]:=div10[i-1];
    end;


  read(test);
  for test:=1 to test do
    begin
      read(n);
      u:=MAXN+1; nho:=0;

      for i:=1 to n do
        begin
          dec(u);
          a[u]:=mod10[i+nho];
          nho:=div10[i+nho];
        end;

      for i:=n-1 downto 1 do
        begin
          dec(u);
          a[u]:=mod10[i+nho];
          nho:=div10[i+nho];
        end;

      while (nho>0) do
        begin
          dec(u);
          a[u]:=mod10[nho];
          nho:=div10[nho];
        end;

      for i:=u to MAXN do write(a[i]);
      writeln;
    end;
end.

Code mẫu của hieult

#include <stdio.h>
//#include <conio.h>
main()
 {
 long T,n;
 scanf("%ld",&T);
 for(long i=0;i<T;i++)
   {
   scanf("%ld",&n);
   if(n==1)
     printf("1\n");
   else if(n<10)
     {
     for(int j=1;j<=n;j++)
       printf("%d",j);
     for(int j=1;j<n-1;j++)
       printf("%d",n-j);
     printf("1\n");
     }
   else
     {
     for(long j=1;j<=(n-1)/9;j++)
       printf("123456790");
     if((n-1)%9!=0)
       {
       for(long j=1;j<=(n-1)%9+1;j++)
         printf("%ld",j);
       for(long j=1;j<=(n-1)%9-1;j++)
         printf("%ld",(n-1)%9+1-j);
       }
     for(long j=1;j<=(n-1)/9;j++)
       printf("098765432");
     printf("1\n");
     }                        
   }
 //getch();
 }

Code mẫu của khuc_tuan

#include "stdio.h"

      #define maxn 2000222

      int n;
      int a[maxn];
      char o[maxn];

      int main() {
            int t;
            scanf("%d", &t);
            while((t--)>0) {
                scanf("%d", &n);
                int nho=0;
                for(int i=1;i<=n;++i) {
                      nho = nho + i;
                      a[i] = nho%10;
                      nho = nho/10;
                }                      
                for(int i=n-1;i>=1;--i) {
                      nho = nho + i;
                      a[n+n-i] = nho%10;
                      nho = nho/10;
                }
                int id=2*n-1;
                while(nho>0) {
                      a[++id] = nho%10;
                      nho = nho/10;
                }

                n=0;
                for(int i=id;i>=1;--i) {
                    o[n++]=a[i]+'0';
                }    
                o[n]=0;
                printf("%s",o);
                printf("\n");
            }                
            return 0;
      }

Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.