-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
814 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
123c | ||
0123dd | ||
|
||
-45ed | ||
e1321 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
123 | ||
123 | ||
-1 | ||
0 | ||
0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# 编写函数:String to Integer (I) (Append Code) | ||
Time Limit: 1 Sec Memory Limit: 2 MB | ||
|
||
|
||
## Description | ||
|
||
让我们来编写一个程序,按照指定的转换规则,把一个字符串里的整数提取出来。 | ||
|
||
----------------------------------------------------------------------------- | ||
编写函数strToInt(): | ||
原型:int strToInt(char str[]); | ||
功能:按照指定的转换规则,把str[]中的串转换成整数,并返回,若str[]为空串,返回-1。 | ||
函数的调用格式见“Append Code”。 | ||
----------------------------------------------------------------------------- | ||
Invalid Word(禁用单词)错误:在解决这个题目时,某些关键词是不允许被使用的。如果提交的程序中包含了下列的关键词之一,就会产生这个错误。 | ||
被禁用的库函数:sscanf()、atoi()、atof()、atol()、strtod()、strtold()、strtof()、strtol()、strtoul()等。 | ||
|
||
|
||
## Input | ||
输入是多行,每行一个字符串s,至EOF结束。每个串s不超过10个字符,并且s转换后的整数不会超出int类型的表示范围。 | ||
s的转换规则是:从第一个字符开始的前若干个连续数字字符("0"~"9")转换为一个无符号的十进制整数,直到第一个非数字字符为止。从第一个非数字字符开始,都是非法字符。因此,如果一个串全部都是非法字符,那么它只能是0。 | ||
|
||
## Output | ||
输出为多行,与输入对应。每行输出是串s转换后的一个整数。 | ||
|
||
## Sample Input | ||
``` | ||
123c | ||
0123dd | ||
-45ed | ||
e1321 | ||
``` | ||
## Sample Output | ||
``` | ||
123 | ||
123 | ||
-1 | ||
0 | ||
0 | ||
``` | ||
|
||
## HINT | ||
“Append Code”中用到的头文件、全局变量或宏的定义应自行补充。 | ||
|
||
## Append Code | ||
### append.c | ||
```c | ||
int main() | ||
{ | ||
char s[MAX_STR_LEN]; | ||
while(gets(s) != NULL) | ||
printf("%d\n", strToInt(s)); | ||
return 0; | ||
} | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
123c | ||
0123dd | ||
|
||
-45ed | ||
e1321 | ||
+76abcdef |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
123 | ||
123 | ||
0 | ||
-45 | ||
0 | ||
76 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# 编写函数:String to Integer (II) (Append Code) | ||
Time Limit: 1 Sec Memory Limit: 2 MB | ||
|
||
|
||
## Description | ||
|
||
让我们来编写一个程序,按照指定的转换规则,把一个字符串里的整数提取出来。 | ||
|
||
----------------------------------------------------------------------------- | ||
编写函数strToInt(): | ||
原型:int strToInt(char str[]); | ||
功能:按照指定的转换规则,把str[]中的串转换成整数,并返回。 | ||
函数的调用格式见“Append Code”。 | ||
----------------------------------------------------------------------------- | ||
Invalid Word(禁用单词)错误:在解决这个题目时,某些关键词是不允许被使用的。如果提交的程序中包含了下列的关键词之一,就会产生这个错误。 | ||
被禁用的库函数:sscanf()、atoi()、atof()、atol()、strtod()、strtold()、strtof()、strtol()、strtoul()等。 | ||
|
||
|
||
## Input | ||
输入是多行,每行一个字符串s,至EOF结束。每个串s不超过10个字符,并且s转换后的整数不会超出int类型的表示范围。 | ||
s的转换规则是:从第一个字符开始的前若干个连续数字字符("0"~"9")和仅能出现在s首位的符号位("+"和"-")转换为一个十进制整数,直到第一个非数字字符为止。从第一个非数字字符开始(除了首位的"+"和'-'),都是非法字符。因此,如果一个串全部都是非法字符,那么它只能是0。 | ||
|
||
## Output | ||
输出为多行,与输入对应。每行输出是串s转换后的一个整数。 | ||
|
||
## Sample Input | ||
``` | ||
123c | ||
0123dd | ||
-45ed | ||
e1321 | ||
+76abcdef | ||
``` | ||
## Sample Output | ||
``` | ||
123 | ||
123 | ||
0 | ||
-45 | ||
0 | ||
76 | ||
``` | ||
|
||
## HINT | ||
“Append Code”中用到的头文件、全局变量或宏的定义应自行补充。 | ||
|
||
## Append Code | ||
### append.c | ||
```c | ||
int main() | ||
{ | ||
char s[MAX_STR_LEN]; | ||
while(gets(s) != NULL) | ||
printf("%d\n", strToInt(s)); | ||
return 0; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include<math.h> | ||
|
||
int main() | ||
{ | ||
int f; | ||
long long int k,jc=1,sum=0,i,j; | ||
scanf("%lld",&k); | ||
for(i=1;i<=k;i++) | ||
{ | ||
jc=1; | ||
for(j=1;j<=i;j++) | ||
{ | ||
jc=jc*j; | ||
} | ||
sum=sum+jc; | ||
if(sum>2455009817) | ||
{f=1; | ||
break;} | ||
} | ||
if(f==1) | ||
printf("overflow"); | ||
else | ||
printf("%lld",sum); | ||
return 0; | ||
} | ||
/************************************************************** | ||
Problem: 1029 | ||
User: 201901060819 | ||
Language: C++ | ||
Result: Accepted | ||
Time:0 ms | ||
Memory:800 kb | ||
****************************************************************/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
int main() | ||
{ | ||
int i,j,s; | ||
int n; | ||
scanf("%d",&n); | ||
printf("Sun Mon Tue Wen Thu Fri Sat\n"); | ||
if(n==7) | ||
{ | ||
for(i=1; i<=7; i++) | ||
{ | ||
printf("%3d",i); | ||
if(i!=7) | ||
printf(" "); | ||
} | ||
printf("\n"); | ||
for(i=8; i<=14; i++) | ||
{ | ||
printf("%3d",i); | ||
if(i!=14) | ||
printf(" "); | ||
} | ||
printf("\n"); | ||
for(i=15; i<=21; i++) | ||
{ | ||
printf("%3d",i); | ||
if(i!=21) | ||
printf(" "); | ||
} | ||
printf("\n"); | ||
for(i=22; i<=28; i++) | ||
{ | ||
printf("%3d",i); | ||
if(i!=28) | ||
printf(" "); | ||
} | ||
printf("\n"); | ||
for(i=29; i<=30; i++) | ||
{ | ||
printf("%3d",i); | ||
if(i!=30) | ||
printf(" "); | ||
} | ||
} | ||
else | ||
{ | ||
for(i=1; i<=4*n; i++) | ||
{ | ||
printf(" "); | ||
} | ||
s=1; | ||
for(j=7-n; j<=50; j+=7) | ||
{ | ||
if(i==30) | ||
{break;} | ||
for(i=s; i<=j; i++) | ||
{ | ||
if(i==30) | ||
{ | ||
printf("%3d",i); | ||
break; | ||
} | ||
else if(i!=j) | ||
{ | ||
printf("%3d",i); | ||
printf(" "); | ||
} | ||
s=j+1; | ||
if(i==j) | ||
{ | ||
printf("%3d",i); | ||
printf("\n"); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
return 0; | ||
} | ||
/************************************************************** | ||
Problem: 1100 | ||
User: 201901060819 | ||
Language: C | ||
Result: Accepted | ||
Time:0 ms | ||
Memory:748 kb | ||
****************************************************************/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
|
||
int main() | ||
{ | ||
int N; | ||
long long int i,x,a[100001]={0}; | ||
long long int min,max; | ||
long long int m; | ||
while(scanf("%d",&N)!=EOF) | ||
{ | ||
if(N==0) | ||
break; | ||
for(i=0;i<N;i++) | ||
{ | ||
scanf("%lld",&x); | ||
a[i]=x; | ||
} | ||
min=a[0]; | ||
for(i=0;i<N;i++) | ||
{ | ||
if(a[i]<min) | ||
min=a[i]; | ||
} | ||
max=a[0]; | ||
for(i=0;i<N;i++) | ||
{ | ||
if(a[i]>max) | ||
max=a[i]; | ||
} | ||
m=(max-min)*2; | ||
printf("%lld\n",m); | ||
} | ||
return 0; | ||
} | ||
/************************************************************** | ||
Problem: 1119 | ||
User: 201901060819 | ||
Language: C | ||
Result: Accepted | ||
Time:52 ms | ||
Memory:1456 kb | ||
****************************************************************/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#define MAX_STR_LEN 11 | ||
#include<string.h> | ||
|
||
int strToInt(char str[]) | ||
{ | ||
int x=0,i; | ||
int y; | ||
y=strlen(str); | ||
if(y==0) | ||
x=-1; | ||
else | ||
{for(i=0;str[i]!='/0';i++) | ||
{ | ||
if(str[i]>='0'&&str[i]<='9') | ||
x=(str[i]+x*10)-'0'; | ||
else | ||
break; | ||
} | ||
} | ||
return x; | ||
} | ||
|
||
int main() | ||
{ | ||
char s[MAX_STR_LEN]; | ||
while(gets(s) != NULL) | ||
printf("%d\n", strToInt(s)); | ||
return 0; | ||
} | ||
|
||
/************************************************************** | ||
Problem: 1133 | ||
User: 201901060819 | ||
Language: C | ||
Result: Accepted | ||
Time:0 ms | ||
Memory:748 kb | ||
****************************************************************/ | ||
|
Oops, something went wrong.