1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

自分専用、2桁、3桁、4桁で数字の前に「0」ゼロを付ける。

Last updated at Posted at 2025-04-20

いろいろ、注意

  • UNO での 予定は、未定

プログラム

オンラインコンパイラpaiza


#include <iostream>
using namespace std;

void z4(char *str){
    if(str[0] == 0) return;
    if(str[1] == 0) {
        str[4] = 0;
        str[3] = str[0];
        str[2] = '0';
        str[1] = '0';
        str[0] = '0';
        return;
    }
    if(str[2] == 0) {
        str[4] = 0;
        str[3] = str[1];
        str[2] = str[0];
        str[1] = '0';
        str[0] = '0';
        return;
    }
    if(str[3] == 0) {
        str[4] = 0;
        str[3] = str[2];
        str[2] = str[1];
        str[1] = str[0];
        str[0] = '0';
        return;
    }
}

void z3(char *str){
    if(str[0] == 0) return;
    if(str[1] == 0) {
        str[3] = 0;
        str[2] = str[0];
        str[1] = '0';
        str[0] = '0';
        return;
    }
    if(str[2] == 0) {
        str[3] = 0;
        str[2] = str[1];
        str[1] = str[0];
        str[0] = '0';
        return;
    }
}

void z2(char *str){
    if(str[0] == 0) return;
    if(str[1] == 0) {
        str[2] = 0;
        str[1] = str[0];
        str[0] = '0';
        return;
    }
}

int main(void){
    // Your code here!
    char a1[16] =    "1";z4(a1);printf(a1);printf("\n");
    char a2[16] =   "12";z4(a2);printf(a2);printf("\n");
    char a3[16] =  "123";z4(a3);printf(a3);printf("\n");
    char a4[16] = "1234";z4(a4);printf(a4);printf("\n");

    char b1[16] =    "1";z3(b1);printf(b1);printf("\n");
    char b2[16] =   "12";z3(b2);printf(b2);printf("\n");
    char b3[16] =  "123";z3(b3);printf(b3);printf("\n");

    char c1[16] =    "1";z2(c1);printf(c1);printf("\n");
    char c2[16] =   "12";z2(c2);printf(c2);printf("\n");
}



0001
0012
0123
1234
001
012
123
01
12

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?