More actions
imported>heoay No edit summary |
(Repair batch-0003 pages from live compare) |
||
| Line 28: | Line 28: | ||
int process(int n1, int n2) | int process(int n1, int n2) | ||
{ | { | ||
int nums1 | int nums1[11], nums2[11]; | ||
int i, max_len, big_num, small_num, num1_len, num2_len, operation = 0; | int i, max_len, big_num, small_num, num1_len, num2_len, operation = 0; | ||
num1_len = numlen(n1); | num1_len = numlen(n1); | ||
| Line 49: | Line 49: | ||
for(i = numlen(small_num); i <= max_len+1; i++) | for(i = numlen(small_num); i <= max_len+1; i++) | ||
{ | { | ||
nums2 | nums2[i] = 0; | ||
} | } | ||
nums1 | nums1[max_len] = 0; | ||
nums2 | nums2[max_len+1] = 0; | ||
for(i = 0; i < numlen(big_num); i++) // 나누어 넣기 | for(i = 0; i < numlen(big_num); i++) // 나누어 넣기 | ||
{ | { | ||
nums1 | nums1[i] = big_num / pow(10, i); | ||
nums1 | nums1[i] = nums1[i] % 10; | ||
} | } | ||
for(i = 0; i < numlen(small_num); i++) // 나누어 넣기 | for(i = 0; i < numlen(small_num); i++) // 나누어 넣기 | ||
{ | { | ||
nums2 | nums2[i] = small_num / pow(10, i); | ||
nums2 | nums2[i] = nums2[i] % 10; | ||
} | } | ||
for(i = 0; i < max_len; i++) | for(i = 0; i < max_len; i++) | ||
{ | { | ||
if((nums1 | if((nums1[i]+nums2[i]) >= 10) | ||
{ | { | ||
++operation; | ++operation; | ||
nums1 | nums1[i+1] += 1; | ||
} | } | ||
} | } | ||
| Line 88: | Line 88: | ||
//output | //output | ||
if(operation == 0) | if(operation == 0) | ||
cout << | cout << "No carry operation." << endl; | ||
else if(operation == 1) | else if(operation == 1) | ||
cout << | cout << "1 carry operation." << endl; | ||
else | else | ||
cout << operation << | cout << operation << " carry operations." << endl; | ||
} | } | ||
| Line 100: | Line 100: | ||
---- | ---- | ||
PrimaryArithmatic | |||
Latest revision as of 00:29, 27 March 2026
느낌
2006-01-10 Accepted 0.273 452 역시 실수였었다. 암튼 통과 ~ ㅋㅋ
잘못된 습관1. 무조건 코드짠다- (설계하지 않고) 문제점1 -> 나중에 고쳐야 할 것이 많다. 생각하지 못했던 것들을 수정하느라 시간이 더 많이 간다. 고치자 !!!
코드
#include <iostream>
using namespace std;
#include <math.h>
int numlen(int num)
{
int turn = 0;
while(num >= 10)
{
num /= 10;
turn++;
}
return (turn+1);
}
int process(int n1, int n2)
{
int nums1[11], nums2[11];
int i, max_len, big_num, small_num, num1_len, num2_len, operation = 0;
num1_len = numlen(n1);
num2_len = numlen(n2);
if(num1_len > num2_len)
max_len = num1_len;
else
max_len = num2_len;
if(n1 >= n2)
{
big_num = n1;
small_num = n2;
} else {
big_num = n2;
small_num = n1;
}
for(i = numlen(small_num); i <= max_len+1; i++)
{
nums2[i] = 0;
}
nums1[max_len] = 0;
nums2[max_len+1] = 0;
for(i = 0; i < numlen(big_num); i++) // 나누어 넣기
{
nums1[i] = big_num / pow(10, i);
nums1[i] = nums1[i] % 10;
}
for(i = 0; i < numlen(small_num); i++) // 나누어 넣기
{
nums2[i] = small_num / pow(10, i);
nums2[i] = nums2[i] % 10;
}
for(i = 0; i < max_len; i++)
{
if((nums1[i]+nums2[i]) >= 10)
{
++operation;
nums1[i+1] += 1;
}
}
return operation;
}
int main()
{
int n1, n2, operation;
while(cin >> n1 >> n2)
{
if(n1 == 0 && n2 == 0)
break;
operation = process(n1,n2);
//output
if(operation == 0)
cout << "No carry operation." << endl;
else if(operation == 1)
cout << "1 carry operation." << endl;
else
cout << operation << " carry operations." << endl;
}
return 0;
}
PrimaryArithmatic