메뉴 건너뛰기

Programing

Code Up

1128

관리자 2020.04.06 19:35 조회 수 : 72

C언어

#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std;

int first[10010],secend[10010],buho=0,buho2=0,e=0;

int i=0,cnt=0,cnt2=0;

char str[110];

void reverseString(char* s) {

  size_t size_ = strlen(s);

  char temp;

 

  for (size_t i = 0; i < size_ / 2; i++) {

    temp = s[i];

    s[i] = s[(size_ - 1) - i];

    s[(size_ - 1) - i] = temp;

  }

  if(e==0&&buho==1){

    s[size_-1]='\0';

  }

  if(e==1&&buho2==1)

    s[size_-1]='\0';

}

int main()

{

    scanf("%s",str);

    if(str[0]=='-'){

        buho++;

    }

    reverseString(str);

    while(str[i]!='\0'){

        first[i]=(int)str[i]-48;

        cnt++;

        i++;

    }

    str[0]='1';

    str[1]='2';

    str[2]='3';

    str[3]='4';

    str[4]='5';

    str[5]='6';

    str[6]='7';

    str[7]='8';

    str[8]='9';

    str[9]='\0';

    if(str[0]=='-'){

        buho2++;

    }

    e=1;

    reverseString(str);

    i=0;

    while(str[i]!='\0'){

        int c=(int)str[i]-48;

        for(int j=0;j<=cnt;j++){

            secend[j+i]+=first[j]*c;

        }

        cnt2++;

        i++;

    }

    buho+=buho2;

    for(int j=1;j<=10009;j++)

    {

        secend[j]+=secend[j-1]/10;

        secend[j-1]=secend[j-1]%10;

    }

    int a=1;

    for(int j=10009;j>=0;j--)

    {

        if(a==1&&secend[j]!=0){

            a=0;

        }

    }

    if(a==1){

        printf("0");

        return 0;

    }

    a=1;

    if(buho==1){

        printf("-");

    }

    for(int j=10009;j>=0;j--)

    {

        if(a==1&&secend[j]!=0){

            a=0;

        }

        if(a==1&&secend[j]==0)

            continue;

        printf("%d",secend[j]);

    }

 

    return 0;

}

 

 

번호 제목 글쓴이 날짜 조회 수
공지 안내사항 관리자 2019.12.02 175
142 1154 관리자 2019.12.20 6
141 1153 관리자 2019.12.20 6
140 1152 관리자 2019.12.20 81
139 1151 관리자 2019.12.20 6
138 1150 관리자 2019.12.20 6
137 1149 관리자 2019.12.20 9
136 1148 관리자 2019.12.20 6
135 1147 관리자 2019.12.20 7
134 1144 관리자 2019.12.20 6
133 1143 관리자 2019.12.20 6
132 1140 관리자 2019.12.20 7
131 1139 관리자 2019.12.20 7
130 1138 관리자 2019.12.20 7
129 1137 관리자 2019.12.20 4
128 1136 관리자 2019.12.20 7
127 1135 관리자 2019.12.20 7
126 1133 관리자 2019.12.20 17
125 1132 관리자 2019.12.20 7
124 1131 관리자 2019.12.20 6
» 1128 관리자 2020.04.06 72
122 1127 관리자 2019.12.20 7
121 1126 관리자 2019.12.20 7
120 1125 관리자 2019.12.20 7
119 1124 관리자 2019.12.20 6
118 1123 관리자 2019.12.20 8
117 1122 관리자 2019.12.20 8
116 1121 관리자 2019.12.20 8
115 1120 관리자 2019.12.20 9
114 1119 관리자 2019.12.20 8
113 1118 관리자 2019.12.20 8
위로