[C언어] PAT 갑급 훈련 문제 1001문제 총결산
1208 단어 PAT
링크:원제
원제 내용:
Calculate a+b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).
Input Specification:
Each input file contains one test case. Each case contains a pair of integers a and b where -10≤a,b≤10.
The numbers are separated by a space.
Output Specification:
For each test case, you should output the sum of a and b in one line. The sum must be written in the standard format.
Sample Input:
-1000000 9
Sample Output:
-999,991
대답:
#include
#include
int main()
{
int i,j,a,b,sum,num1,num2;
int num[8];
i=0;
scanf("%d%d",&a,&b);
sum=a+b;
if(sum<0)
printf("-");
if(sum==0){
printf("0");
exit(0); //special
}
while(sum)
{
num[i]=abs(sum%10);
i++;
sum/=10;
}
for (j=i-1;j>=0;j--)
{
printf("%d",num[j]);
if(j%3==0 && j!=0)
printf(",");
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
PAT A급 1064 Complete Binary Search Tree(30점) 완전 두 갈래 나무, BST1064 Complete Binary Search Tree(30분) A Binary Search Tree (BST) is recursively defined as a binary tree which has the f...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.