八个比特

HDUOJ笔记

字数统计: 327阅读时长: 1 min
2019/04/07 Share

Problem 1000:A + B Problem
Problem Description
Calculate A + B.

Input
Each line will contain two integers A and B. Process to end of file.

Output
For each case, output A + B in one line.

1
2
3
4
5
6
7
#include <stdio.h>
int main(){
int a,b;
scanf("%d% %d",&a,&b);
printf("%d\n",a+b);
return 0;
}

第一题其实我submit就是wrong answer,主要注意格式,输出要加上换行符;


Problem 1001:Sum Problem
Problem Description
Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).
In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + … + n.

Input
The input will consist of a series of integers n, one integer per line.

Output
For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.

1
2
3
4
5
6
7
8
9
10
#include<stdio.h>
int main(){
int m;
while(scanf("%d",&m)!=EOF){
int sum=0;
for(int k=0;k<=m;k++) sum+=k;
printf("%d\n\n",sum);
}
return 0;
}

要是数字大点的话用递归做大概会超出深度


1122334455+9988776655
66778899+44332211

111111110
11111111110

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>
#include <string.h>
int main()
{
int n;
scanf("%d%",&n);
while(n--)
{
char str1[]={0};
char str2[]={0};
char str3[]={0};
puts(str1);
puts(str2);
if(strlen(str1)>=strlen(str2))
{
int m=strlen(str2)-1;
int flag=0;
for(int a=m;a>0;a--)
{
int num=int(str1[m])+int(str2[m])+flag;
if(num>=10)
{
add=num%10;
flag=1;
}
else
{
add=num;
flag=0;
}
strcat(char(add),str3);
}
}
}
return 0;
}

CATALOG