5.8.4
This commit is contained in:
parent
bfe7d4905a
commit
aeb9c19ba0
BIN
Test/.DS_Store
vendored
Normal file
BIN
Test/.DS_Store
vendored
Normal file
Binary file not shown.
133
Test/2019ACM/!!!! 小z的偶数之和.c
Executable file
133
Test/2019ACM/!!!! 小z的偶数之和.c
Executable file
@ -0,0 +1,133 @@
|
||||
/*
|
||||
Description
|
||||
小z现在落在一个n*m的地图里,每个位置都有一个数字, 由于最近小z的方向感堪忧, 他只能从出发点(x,y)向一个确定的方向前进,不然他可能会迷路的. 现在他可以向8个方向前进: 上,下,左,右,左上,左下,右上,右下,走到边界就会传送回出发点. 小z的好朋友小y特别喜欢偶数, 就希望小z能带回尽可能大的偶数之和.现在小z请求你写个程序帮助他完成这个任务.
|
||||
|
||||
Input
|
||||
首先两个整数n,m(1 <= n,m <= 1000) 代表地图的大小, 接下来n行,每行m个数字a[i][j],1 <= a[i][j] <= 10^9代表地图中的每个值.最后两个整数x,y (1 <= x <= n, 1 <= y <= m)代表小z现在所在的位置.
|
||||
|
||||
Output
|
||||
一行,包括一个整数,代表小z最多能带回的最大偶数之和
|
||||
|
||||
Sample
|
||||
Input
|
||||
3 4
|
||||
1 2 3 4
|
||||
1 2 3 4
|
||||
1 2 3 4
|
||||
2 2
|
||||
Output
|
||||
6
|
||||
Hint
|
||||
一个偶数只能被带走一次
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
long long int i,n,m,j,x,t=0,y,max=0;
|
||||
long long map[1000][1000],sum[8]={0};
|
||||
|
||||
scanf("%lld %lld",&n,&m);
|
||||
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
for(j=0;j<m;j++)
|
||||
{
|
||||
scanf("%lld",&map[i][j]);
|
||||
}
|
||||
}
|
||||
|
||||
scanf("%lld %lld",&x,&y);
|
||||
x=x-1;
|
||||
y=y-1;
|
||||
|
||||
if (map[y][x]%2==0)
|
||||
{
|
||||
t=map[y][x];
|
||||
map[y][x]=1;
|
||||
}
|
||||
for(i=y;i<n;i++)//向下
|
||||
{
|
||||
if (map[i][x]%2==0)
|
||||
{
|
||||
sum[0]+=map[i][x];
|
||||
map[i][x]=1;
|
||||
}
|
||||
}
|
||||
|
||||
for(i=y;i>=0;i--)//向上
|
||||
{
|
||||
if (map[i][x]%2==0)
|
||||
{
|
||||
sum[1]+=map[i][x];
|
||||
map[i][x]=1;
|
||||
}
|
||||
}
|
||||
|
||||
for(i=x;i>=0;i--)//向左
|
||||
{
|
||||
if (map[y][i]%2==0)
|
||||
{
|
||||
sum[2]+=map[y][i];
|
||||
map[y][i]=1;
|
||||
}
|
||||
}
|
||||
for(i=x;i<m;i++)//向右
|
||||
{
|
||||
if (map[y][i]%2==0)
|
||||
{
|
||||
sum[3]+=map[y][i];
|
||||
map[y][i]=1;
|
||||
}
|
||||
}
|
||||
|
||||
for(i=y,j=x;i>=0&&j<m;i--,j++)//向右上
|
||||
{
|
||||
if (map[i][j]%2==0)
|
||||
{
|
||||
sum[4]+=map[i][j];
|
||||
map[i][j]=1;
|
||||
}
|
||||
}
|
||||
|
||||
for(i=y,j=x;i>=0&&j>=0;i--,j--)//向左上
|
||||
{
|
||||
if (map[i][j]%2==0)
|
||||
{
|
||||
sum[5]+=map[i][j];
|
||||
map[i][j]=1;
|
||||
}
|
||||
}
|
||||
|
||||
for(i=y,j=x;i<n&&j>=0;i++,j--)//向左下
|
||||
{
|
||||
if (map[i][j]%2==0)
|
||||
{
|
||||
sum[6]+=map[i][j];
|
||||
map[i][j]=1;
|
||||
}
|
||||
}
|
||||
for(i=y,j=x;i<n&&j<m;i++,j++)//向右下
|
||||
{
|
||||
if (map[i][x]%2==0)
|
||||
{
|
||||
sum[7]+=map[i][x];
|
||||
map[i][x]=1;
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0;i<8;i++)
|
||||
{
|
||||
if(sum[i]>max)
|
||||
{
|
||||
max=sum[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (t!=0)
|
||||
{
|
||||
max=max+t;
|
||||
}
|
||||
|
||||
printf("%lld",max);
|
||||
return 0;
|
||||
}
|
BIN
Test/2019ACM/.DS_Store
vendored
Executable file
BIN
Test/2019ACM/.DS_Store
vendored
Executable file
Binary file not shown.
103
Test/2019ACM/守卫的DNA.c
Executable file
103
Test/2019ACM/守卫的DNA.c
Executable file
@ -0,0 +1,103 @@
|
||||
/*
|
||||
Description
|
||||
在Ljn计算出了湖深度后,船长Ljj为了奖励Ljn抓了稷下湖所有的鹅给Ljn吃,这个举动严重破坏了稷下湖的生态平衡,湖神为了惩罚他们,把他们关在自闭的荷花里,并由守卫看守。他们为了逃跑和守卫达进行了py交易,他们帮助守卫得出自己的DNA序列,然后守卫帮助他们从荷花中逃走。守卫有一个记录自己DNA序列的字符串,但因为污损其中的部分字符已经看不清以“?”代替,守卫的DNA由“A”“G”“C”“T”四种字符组成,且在字符串中这四个字符的数量都相等,现在你把“?”补充完整,得到守卫的DNA,守卫要求你构造出的字符串是所有情况中字典序最小的,如果存在这种字符串,请输出他,否则输出“impossible”(不包含引号)。
|
||||
|
||||
Input
|
||||
第一行包含一个整数n表示字符串的长度。(1≤n≤1000)
|
||||
|
||||
第二行输入一个长度为n的字符串。
|
||||
|
||||
Output
|
||||
如果能构造出来请输出构造出的字符串。
|
||||
|
||||
否则否则输出“impossible”(不包含引号)。
|
||||
|
||||
Sample
|
||||
Input
|
||||
8
|
||||
AG?C??CT
|
||||
Output
|
||||
AGACGTCT
|
||||
*/
|
||||
#include<stdio.h>
|
||||
#include<string.h>
|
||||
int main()
|
||||
{
|
||||
char dna[1000],fl;
|
||||
int a=0,c=0,g=0,t=0;
|
||||
int len,i,max;
|
||||
|
||||
scanf("%d",&len);
|
||||
getchar();
|
||||
|
||||
if(len%4!=0)
|
||||
{
|
||||
printf("impossible\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
max=len/4;
|
||||
gets(dna);
|
||||
|
||||
for(i=0;i<len;i++)//计数
|
||||
{
|
||||
fl=dna[i];
|
||||
switch(fl)
|
||||
{
|
||||
case 'A':
|
||||
a++;
|
||||
break;
|
||||
case 'G':
|
||||
g++;
|
||||
break;
|
||||
case 'C':
|
||||
c++;
|
||||
break;
|
||||
case 'T':
|
||||
t++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (a>max||c>max||t>max||g>max)
|
||||
{
|
||||
printf("impossible\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(i=0;i<len;i++)
|
||||
{
|
||||
if (dna[i]=='?')
|
||||
{
|
||||
if (a<max)
|
||||
{
|
||||
dna[i]='A';
|
||||
a++;
|
||||
continue;
|
||||
}
|
||||
if (c<max)
|
||||
{
|
||||
dna[i]='C';
|
||||
c++;
|
||||
continue;
|
||||
}
|
||||
if (g<max)
|
||||
{
|
||||
dna[i]='G';
|
||||
g++;
|
||||
continue;
|
||||
}
|
||||
if (t<max)
|
||||
{
|
||||
dna[i]='T';
|
||||
t++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
puts(dna);
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
34
Test/2019ACM/想吃鹅肉? .c
Executable file
34
Test/2019ACM/想吃鹅肉? .c
Executable file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
想吃鹅肉?
|
||||
Description
|
||||
在大航海时代,Ljn和船长Ljj乘坐塞尔号在稷下湖中滑水,Ljn注意到了湖面上有一朵自闭的荷花,走进后发现花苞距离河面高度为H厘米,Ljn又抓住荷花向正前航行了L厘米,在这个点上,自闭的荷花花苞恰好碰到了湖面。假设荷花生长湖底A点,且竖直生长,保证最初花苞正好生长在A点正上方。现在船长Ljj要求Ljn计算湖的深度,算出来后就要请Ljn吃烤鹅肉,Ljn为了能吃更多的鹅肉,想让他帮他写个程序直接计算湖的深度,并输出。
|
||||
|
||||
模型如图:
|
||||
|
||||
|
||||
Input
|
||||
一行包含两个整数H和L(1≤H<L≤1000000)。
|
||||
|
||||
Output
|
||||
输出仅包含一个数——湖的深度(A点到湖面的距离)结果要求保留两位小数。
|
||||
|
||||
Sample
|
||||
Input
|
||||
1 2
|
||||
Output
|
||||
1.50
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
long long int h,l;
|
||||
double d;
|
||||
|
||||
scanf("%lld %lld",&h,&l);
|
||||
|
||||
d=(double)(l*l-h*h)/(2.0*h);
|
||||
|
||||
printf("%.2lf\n",d);
|
||||
|
||||
return 0;
|
||||
}
|
139
Test/2019ACM/机器数.c
Executable file
139
Test/2019ACM/机器数.c
Executable file
@ -0,0 +1,139 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
计算机中的数据,其本质都是以二进制码存储。计算机系统的内存储器,是由许多称为字节的单元组成的,1个字节由8个二进制位构成,每位的取值为0或1。最右端的那1位称为“最低位”;最左端的那1位称为“最高位”。
|
||||
|
||||
数字在计算机中的表示方法有原码、反码和补码。
|
||||
|
||||
原码:最简单的机器数表示法。用最高位表示符号位,‘1’表示负号,‘0’表示正号。其其余位存放该数的绝对值的二进制。
|
||||
|
||||
反码:正数的反码与原码相同,负数的反码符号位为1不变,其余各位按位取反(1变0、0变1)
|
||||
|
||||
补码:正数的补码与原码相同,负数的补码是在其反码的基础上+1。
|
||||
|
||||
本题要求给定一个8位的原码,求出其补码。
|
||||
Input
|
||||
|
||||
第一行一个T(1=<T<=255),表示有T组数据
|
||||
|
||||
以下T行,第i(1=<i<=T)行是一个8位的二进制数,表示一个数的原码
|
||||
Output
|
||||
|
||||
对于每行输入的原码,求出它的补码,并在一行中输出。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
2
|
||||
10101010
|
||||
01010101
|
||||
Output
|
||||
|
||||
11010110
|
||||
01010101
|
||||
Hint
|
||||
|
||||
输入数据不存在负零,也就是说,输入的原码可能是 00000000 ,不会有 10000000
|
||||
*/
|
||||
/*#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
//此处不建议用int因为会有0开头的数,会导致结果少一位,本程序在第20行修补了这一错误
|
||||
//应用字符串型并且因为在ASCII码表中数字是顺序的所以可直接运算
|
||||
int i,num,t,T;
|
||||
int n[8];
|
||||
|
||||
scanf("%d",&T);
|
||||
|
||||
while(T--)
|
||||
{
|
||||
scanf("%d",&num);
|
||||
t=num;
|
||||
for(i=7;t>0;i--)
|
||||
{
|
||||
n[i]=t%10;
|
||||
t=t/10;
|
||||
}
|
||||
if(i==0)//修补因为0开头的数字导致位数减少的问题
|
||||
{
|
||||
n[0]=0;
|
||||
}
|
||||
if (n[0]==1)
|
||||
{
|
||||
for(i=1;i<8;i++)
|
||||
{
|
||||
n[i]=!n[i];//取反
|
||||
}
|
||||
for(i=7;i>0;i--)
|
||||
{
|
||||
if(i==7)
|
||||
{
|
||||
n[i]=n[i]+1;
|
||||
}
|
||||
if (n[i]==2)//逢2进1
|
||||
{
|
||||
n[i]=0;
|
||||
n[i-1]=n[i-1]+1;//进位
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0;i<8;i++)
|
||||
{
|
||||
printf("%d",n[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
char a[8];
|
||||
int t,i;
|
||||
scanf("%d",&t);
|
||||
while (t--)
|
||||
{
|
||||
scanf("%s",a);
|
||||
if (a[0] == '1')
|
||||
{
|
||||
for (i = 1; i < 8; i++)
|
||||
{
|
||||
if (a[i] == '1')
|
||||
{
|
||||
a[i] = '0';
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
a[i] = '1';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (a[0] == '1')
|
||||
|
||||
{
|
||||
for (i = 7; i >= 0 ; i--)
|
||||
{
|
||||
if (i == 7)
|
||||
{
|
||||
a[i] = a[i] + 1;
|
||||
}
|
||||
if (a[i] == '2')
|
||||
{
|
||||
a[i] = '0';
|
||||
a[i - 1] = a[i - 1] + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = 0;i < 8;i++)
|
||||
{
|
||||
printf("%c",a[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
76
Test/2019ACM/生化危机.c
Executable file
76
Test/2019ACM/生化危机.c
Executable file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
由于BHS公司制造了一种病毒,这种病毒可以将死去的人们,变成丧尸,这个公司通过贩卖这种病毒,来获取巨大的利益,而正义的ljj当然会阻止这种行为,在行动中由于失误,将这种病毒泄露了,从而感染了全球。将地球划分成一个由方格组成的地图,包含两个大写字母 W (代表未被感染的地区),B(代表感染的地区),为了让问题变得简单,一开始地球中所有地区都是未被感染的,病毒从一个中心往四周泄露,以正方形进行散,最终正方形边长是奇数,你能帮助 ljj 找到这个中心吗?
|
||||
Input
|
||||
|
||||
输入一个整数N,代表地图一共有N行 (1<= N <=115)
|
||||
|
||||
然后输入N行字符串,每行保证长度一致为M(1 <= M <= 115)
|
||||
|
||||
N行M列中包含两个字母(W,B)分别表示未感染的地区、感染的地区。
|
||||
Output
|
||||
|
||||
输出两个整数,x,y(1<=x<=N,1<=y<=M)代表病毒中心的位置。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
5
|
||||
|
||||
WWBBBW
|
||||
|
||||
WWBBBW
|
||||
|
||||
WWBBBW
|
||||
|
||||
WWWWWW
|
||||
|
||||
WWWWWW
|
||||
Output
|
||||
|
||||
2 4
|
||||
*/
|
||||
#include<stdio.h>
|
||||
#include<string.h>
|
||||
int main()
|
||||
{
|
||||
int n,i,j,up=0,left=0,down=0,right=0;
|
||||
char str[115][115];
|
||||
int x,y;
|
||||
long int len;
|
||||
scanf("%d",&n);
|
||||
getchar();//吃回车
|
||||
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
gets(str[i]);//自动换列
|
||||
//scanf("%s",str[i]);也可
|
||||
}
|
||||
len = strlen(str[0]);
|
||||
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
for(j=0;j<len;j++)
|
||||
{
|
||||
if (str[i][j]=='B')
|
||||
{
|
||||
if (!up && !left)//! 代表值得取反,对于整形变量,只要不为0,使用 ! 取反都是0,0取反就是1
|
||||
{
|
||||
left = j+1;
|
||||
up = i+1;
|
||||
}
|
||||
right = j + 1;
|
||||
down = i+1;
|
||||
}
|
||||
//循环结束后便记录下了最后一个点的位置
|
||||
}
|
||||
}
|
||||
|
||||
x=(right+left)/2;
|
||||
y=(down+up)/2;
|
||||
|
||||
printf("%d %d\n",y,x);
|
||||
|
||||
return 0;
|
||||
}
|
59
Test/C/程序设计基础I/OJE 偶数数位求和.c
Executable file
59
Test/C/程序设计基础I/OJE 偶数数位求和.c
Executable file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
给定一个整数,请求出这个整数所有数位中是偶数的数位的和。例如,对于12436546,那么答案就是 2 + 4 + 6 + 4 + 6 。
|
||||
Input
|
||||
|
||||
输入一个数 n 。 (0 <= n <= 2147483647)
|
||||
Output
|
||||
|
||||
输出 n 的所有偶数数位的和。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
6768
|
||||
Output
|
||||
|
||||
20
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int n, temp, i, temp2, c=0;
|
||||
|
||||
scanf("%d", &n);
|
||||
|
||||
i = 0;
|
||||
while (n>=10)
|
||||
{
|
||||
temp=0;
|
||||
|
||||
temp2=0;
|
||||
|
||||
temp = n%10;
|
||||
|
||||
temp2 = temp%2;
|
||||
|
||||
if (temp2 == 0)
|
||||
{
|
||||
i = i+temp;
|
||||
}
|
||||
else
|
||||
c = c+1;
|
||||
|
||||
n = n/10;
|
||||
|
||||
}
|
||||
c = 0;
|
||||
c = n%2;
|
||||
if (c == 0)
|
||||
{
|
||||
i = i + n;
|
||||
printf("%d\n",i);
|
||||
}
|
||||
else
|
||||
printf("%d\n", i);
|
||||
|
||||
return 0;
|
||||
}
|
60
Test/C/程序设计基础I/OJI 时间格式转换.c
Executable file
60
Test/C/程序设计基础I/OJI 时间格式转换.c
Executable file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
24 小时制的时间格式为 "HH:mm",如 “05:20”,而 12 小时制的时间格式为 "h:mm AM/PM",如 "5:20 AM"。
|
||||
|
||||
24 小时制到 12 小时制的对应关系如下:
|
||||
|
||||
0 时:12 时 (AM)
|
||||
1~11 时:1~11 时 (AM)
|
||||
12 时:12 时 (PM)
|
||||
13~23 时:1~11 时 (PM)
|
||||
例如:"00:00" 对应 "12:00 AM","01:20" 对应 "1:20 AM","12:35" 对应 "12:35 PM","13:17" 对应 "1:17 PM","23:59" 对应 "11:59 PM"。
|
||||
|
||||
|
||||
|
||||
现在给你一个 24 小时制的时间,请你编写程序将其转换为 12 小时制的时间。
|
||||
Input
|
||||
|
||||
输入只有一行,包含一个 24 小时制的时间。
|
||||
Output
|
||||
|
||||
输出一行,表示转换为 12 小时制以后的时间。其中分钟部分若不足两位需要加 0 补足两位。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
00:05
|
||||
Output
|
||||
|
||||
12:05 AM
|
||||
Hint
|
||||
|
||||
输入部分可以使用 scanf("%d:%d") 读入;输出的数字部分可以使用 printf("%d:%02d") 输出。
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main ()
|
||||
{
|
||||
int h1, m1;
|
||||
|
||||
int h2;
|
||||
|
||||
scanf("%d:%02d", &h1, &m1);
|
||||
|
||||
h2 = h1 - 12;
|
||||
|
||||
if (h1 == 12)
|
||||
printf("%d:%02d PM\n", h1, m1);
|
||||
else if (h1 == 0)
|
||||
printf("%d:%02d AM\n", -h2, m1);
|
||||
else
|
||||
{
|
||||
if (h2 < 0)
|
||||
printf("%2d:%02d AM\n", h1, m1);
|
||||
|
||||
else
|
||||
printf("%2d:%02d PM\n", h2, m1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
24
Test/C/程序设计基础I/字符串排序.c
Executable file
24
Test/C/程序设计基础I/字符串排序.c
Executable file
@ -0,0 +1,24 @@
|
||||
|
||||
#include<stdio.h>
|
||||
#include<string.h>
|
||||
int main()
|
||||
{
|
||||
int n,i,j;
|
||||
char s[3][110],t[110];
|
||||
for(i=0;i<3;i++)
|
||||
scanf("%s",s[i]);
|
||||
for(i=0;i<2;i++)
|
||||
for(j=i+1;j<3;j++)
|
||||
if(strcmp(s[i],s[j])>0)
|
||||
{
|
||||
strcpy(t,s[i]);
|
||||
strcpy(s[i],s[j]);
|
||||
strcpy(s[j],t);
|
||||
}
|
||||
for(i=0;i<3;i++)
|
||||
{
|
||||
if(i==2) printf("%s\n",s[i]);
|
||||
else printf("%s ",s[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
30
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-10转换字母(顺序结构).c
Executable file
30
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-10转换字母(顺序结构).c
Executable file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
从键盘上输入一个小写字母,然后将小写字母装换成大写字母输出!
|
||||
Input
|
||||
|
||||
从键盘上输入一个小写字母。
|
||||
Output
|
||||
|
||||
小写字母装换成大写字母输出。
|
||||
|
||||
解题思路:
|
||||
将一个小写字符转换成大写字符,只需要将这个字符ASCII减去32;将一个大写字符转换成小写字符,则给这个字符ASCII加上32
|
||||
A => a -32
|
||||
a => A +32
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
|
||||
char a;
|
||||
|
||||
a = getchar();
|
||||
|
||||
a = a - 32;
|
||||
|
||||
putchar(a);
|
||||
|
||||
return 0;
|
||||
}
|
42
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-11实数的输出和占位.c
Executable file
42
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-11实数的输出和占位.c
Executable file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
输入一个实数,请你按如下要求输出:
|
||||
|
||||
第一行按双精度默认输出,
|
||||
|
||||
第二行双精度数输出共占 10 位,其中 3 位小数,右对齐,左补空格并在两端添加星号包裹,
|
||||
|
||||
第三行双精度数输出共占 10 位,其中 3 位小数,左对齐,右补空格并在两端添加星号包裹。
|
||||
Input
|
||||
|
||||
一个double范围内的正实数 a 。
|
||||
Output
|
||||
|
||||
共三行,按题目描述输出。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
123.56789
|
||||
Output
|
||||
|
||||
123.567890
|
||||
* 123.568*
|
||||
*123.568 *
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
double a;
|
||||
|
||||
scanf("%lf",&a);
|
||||
|
||||
printf("%lf\n",a);
|
||||
printf("*%10.3lf*\n",a);
|
||||
printf("*%-10.3lf*\n",a);
|
||||
|
||||
return 0;
|
||||
}
|
25
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-12大整数的输入输出.c
Executable file
25
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-12大整数的输入输出.c
Executable file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
输入两个 long long 范围内的整数,输出他们的和。
|
||||
Input
|
||||
|
||||
两个 long long 范围内的整数。
|
||||
Output
|
||||
|
||||
输出的两个大整数的和,保证结果在 long long 范围内。
|
||||
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
long long a,b,c;
|
||||
|
||||
scanf("%lld %lld", &a, &b);
|
||||
|
||||
c = a + b;
|
||||
|
||||
printf("%lld",c);
|
||||
|
||||
return 0;
|
||||
}
|
37
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-13带’ 和 ”字符的输出.c
Executable file
37
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-13带’ 和 ”字符的输出.c
Executable file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
输入一个字符,输出两行。
|
||||
|
||||
第一行将字符用 ' 包裹。
|
||||
|
||||
第二行将字符用 " 包裹。
|
||||
Input
|
||||
|
||||
输入一个字符。
|
||||
Output
|
||||
|
||||
按题目描述输出。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
A
|
||||
Output
|
||||
|
||||
'A'
|
||||
"A"
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main ()
|
||||
{
|
||||
char a;
|
||||
|
||||
scanf("%c",&a);
|
||||
|
||||
printf("\'%c\'\n",a);
|
||||
printf("\"%c\"",a);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
37
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-14'%'字符的输入输出.c
Executable file
37
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-14'%'字符的输入输出.c
Executable file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
|
||||
Description
|
||||
|
||||
输入三个用 `` \ `` 分割的正整数 a b c 代表日,月,年,
|
||||
|
||||
要求按照输入样式原样输出。
|
||||
Input
|
||||
|
||||
三个int范围内的正整数,中间用 `` \ `` 分割。
|
||||
Output
|
||||
|
||||
按题目描述原样输出。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
9\17\2018
|
||||
Output
|
||||
|
||||
9\17\2018
|
||||
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
|
||||
int a, b, c;
|
||||
char d, e;
|
||||
|
||||
scanf("%d %c %d %c %d",&a, &d, &b, &e, &c);
|
||||
|
||||
printf("%d%c%d%c%d", a, d, b, e, c);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
37
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-15‘\’字符的输入输出.c
Executable file
37
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-15‘\’字符的输入输出.c
Executable file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
|
||||
Description
|
||||
|
||||
输入三个用 `` \ `` 分割的正整数 a b c 代表日,月,年,
|
||||
|
||||
要求按照输入样式原样输出。
|
||||
Input
|
||||
|
||||
三个int范围内的正整数,中间用 `` \ `` 分割。
|
||||
Output
|
||||
|
||||
按题目描述原样输出。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
9\17\2018
|
||||
Output
|
||||
|
||||
9\17\2018
|
||||
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
|
||||
int a, b, c;
|
||||
char d, e;
|
||||
|
||||
scanf("%d %c %d %c %d",&a, &d, &b, &e, &c);
|
||||
|
||||
printf("%d%c%d%c%d", a, d, b, e, c);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
44
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-16十六进制数输出和占位.c
Executable file
44
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-16十六进制数输出和占位.c
Executable file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
|
||||
Description
|
||||
|
||||
输入一个整数,请你按如下要求输出:
|
||||
|
||||
第一行按原样输出,
|
||||
|
||||
第二行以十六进制输出(字母小写),
|
||||
|
||||
第三行以十六进制输出(字母大写)。
|
||||
Input
|
||||
|
||||
一个int范围内的正整数 a 。
|
||||
Output
|
||||
|
||||
共三行,按题目描述输出。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
456
|
||||
Output
|
||||
|
||||
456
|
||||
1c8
|
||||
1C8
|
||||
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int a;
|
||||
|
||||
scanf("%d",&a);
|
||||
|
||||
printf("%d\n",a);
|
||||
printf("%x\n",a);
|
||||
printf("%X\n",a);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
42
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-17八进制数输出和占位.c
Executable file
42
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-17八进制数输出和占位.c
Executable file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
输入一个整数,请你按如下要求输出:
|
||||
|
||||
第一行按原样输出,
|
||||
|
||||
第二行以八进制靠右输出,不足 8 位左补 0 并在两端添加星号包裹,
|
||||
|
||||
第三行以八进制靠左输出,不足 8 位右补空格并在两端添加星号包裹。
|
||||
Input
|
||||
|
||||
一个int范围内的正整数 a 。
|
||||
Output
|
||||
|
||||
共三行,按题目描述输出。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
123
|
||||
Output
|
||||
|
||||
123
|
||||
*00000173*
|
||||
*173 *
|
||||
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int a;
|
||||
|
||||
scanf("%d",&a);
|
||||
|
||||
printf("%d\n",a);
|
||||
printf("*%08o*\n",a);
|
||||
printf("*%-8o*\n",a);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
41
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-18十进制输入输出和其它非空格占位.c
Executable file
41
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-18十进制输入输出和其它非空格占位.c
Executable file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
输入一个整数,请你按如下要求输出:
|
||||
|
||||
第一行按原样输出,
|
||||
|
||||
第二行整数靠右原样输出,不足 8 位左补 0 并在两端添加星号包裹,
|
||||
|
||||
第三行整数靠左原样输出,不足 8 位右补空格并在两端添加星号包裹。
|
||||
Input
|
||||
|
||||
一个int范围内的正整数 a 。
|
||||
Output
|
||||
|
||||
共三行,按题目描述输出。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
123456
|
||||
Output
|
||||
|
||||
123456
|
||||
*00123456*
|
||||
*123456 *
|
||||
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int a;
|
||||
|
||||
scanf("%d",&a);
|
||||
|
||||
printf("%d\n",a);
|
||||
printf("\*%08d\*\n",a);
|
||||
printf("\*%-8d\*\n",a);
|
||||
|
||||
|
||||
}
|
44
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-19十进制输入输出和空格占位.c
Executable file
44
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-19十进制输入输出和空格占位.c
Executable file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
输入一个整数,请你按如下要求输出:
|
||||
|
||||
第一行按原样输出,
|
||||
|
||||
第二行按原样靠右输出,不足 8 位左补空格并在两端添加星号包裹,
|
||||
|
||||
第三行按原样靠左输出,不足 8 位右补空格并在两端添加星号包裹。
|
||||
Input
|
||||
|
||||
一个int范围内的正整数 a 。
|
||||
Output
|
||||
|
||||
共三行,按题目描述输出。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
123456
|
||||
Output
|
||||
|
||||
123456
|
||||
* 123456*
|
||||
*123456 *
|
||||
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int a;
|
||||
|
||||
scanf("%d", &a);
|
||||
|
||||
printf("%d\n", a);
|
||||
printf("*%8d*\n", a);
|
||||
printf("*%-8d*\n", a);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
10
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-1Hello-World!(printf练习).c
Executable file
10
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-1Hello-World!(printf练习).c
Executable file
@ -0,0 +1,10 @@
|
||||
#include<stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
printf("Hello World!");
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
43
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-20字符型数据输出和占位.c
Executable file
43
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-20字符型数据输出和占位.c
Executable file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
输入一个字符,请你按如下要求输出:
|
||||
|
||||
第一行字符数据默认输出,
|
||||
|
||||
第二行字符型数据输出共占 4 位,右对齐,左补 3 个空格并在两端添加星号包裹,
|
||||
|
||||
第三行字符型数据输出共占 4 位,左对齐,右补 3 个空格并在两端添加星号包裹。
|
||||
Input
|
||||
|
||||
输入一个字符 。
|
||||
Output
|
||||
|
||||
共三行,按题目描述输出。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
c
|
||||
Output
|
||||
|
||||
c
|
||||
* c*
|
||||
*c *
|
||||
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
char a;
|
||||
|
||||
scanf("%c", &a);
|
||||
|
||||
printf("%c\n", a);
|
||||
printf("*%4c*\n", a);
|
||||
printf("*%-4c*\n", a);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
17
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-2计算A+B(顺序结构).c
Executable file
17
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-2计算A+B(顺序结构).c
Executable file
@ -0,0 +1,17 @@
|
||||
#include<stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int a;
|
||||
int b;
|
||||
int c;
|
||||
|
||||
scanf("%d %d", &a, &b);
|
||||
|
||||
c = a + b;
|
||||
|
||||
printf("%d",c);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
14
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-3交换两个整数的值(顺序结构).c
Executable file
14
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-3交换两个整数的值(顺序结构).c
Executable file
@ -0,0 +1,14 @@
|
||||
#include<stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int x,y, z;
|
||||
|
||||
scanf("%d %d", &x, &y);
|
||||
z = x;
|
||||
x = y;
|
||||
y = z;
|
||||
|
||||
printf("%d %d",x,y);
|
||||
return 0;
|
||||
}
|
29
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-4逆置正整数.c
Executable file
29
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-4逆置正整数.c
Executable file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
输入一个三位正整数,将它反向输出。
|
||||
Input
|
||||
|
||||
3位正整数。
|
||||
Output
|
||||
|
||||
逆置后的正整数。
|
||||
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int a, b, c, d, e;
|
||||
|
||||
scanf("%d", &a);
|
||||
|
||||
b = a / 100;
|
||||
c = (a / 10 - b * 10);
|
||||
d = a - b * 100 - c * 10;
|
||||
|
||||
e = (d * 100) + (c * 10) + b;
|
||||
|
||||
printf("%d", e);
|
||||
|
||||
return 0;
|
||||
}
|
30
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-5买糖果.c
Executable file
30
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-5买糖果.c
Executable file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
小瑜是个爱吃糖果的馋鬼,天天嚷着要爸爸买糖果,可是爸爸很忙,哪有时间啊,于是就让小瑜自己去了,糖果3角钱一块,爸爸给小瑜n元钱,请你告诉小瑜最多能买几块糖,还剩几角钱?
|
||||
Input
|
||||
|
||||
输入爸爸给小瑜的钱n元,n为整数。
|
||||
Output
|
||||
|
||||
小瑜最多能买回的糖块数以及剩下的钱(单位为:角),用空格分隔。
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int m,n,t,c;
|
||||
|
||||
scanf("%d", &m);
|
||||
|
||||
t = m*10;
|
||||
|
||||
c = t % 3;
|
||||
|
||||
n = t / 3;
|
||||
|
||||
printf("%d %d", n, c);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
18
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-6三个整数的和、积与平均值.c
Executable file
18
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-6三个整数的和、积与平均值.c
Executable file
@ -0,0 +1,18 @@
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int a,b,c,d,e;
|
||||
float f;
|
||||
|
||||
scanf("%d %d %d", &a, &b, &c);
|
||||
|
||||
d = a + b + c;
|
||||
|
||||
e = a * b * c;
|
||||
|
||||
f = (d + 0.00) / 3;
|
||||
|
||||
printf("%d %d %.2f", d, e, f);
|
||||
|
||||
return 0;
|
||||
}
|
18
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-7圆柱体计算.c
Executable file
18
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-7圆柱体计算.c
Executable file
@ -0,0 +1,18 @@
|
||||
#include<stdio.h>
|
||||
int main ()
|
||||
{
|
||||
float pi = 3.1415926;
|
||||
int r,h;
|
||||
float L,S,SC,V;
|
||||
|
||||
scanf("%d %d", &r, &h);
|
||||
|
||||
L = pi * r * 2;
|
||||
S = pi * r * r;
|
||||
SC = L*h;
|
||||
V = S * h;
|
||||
|
||||
printf("%.2f %.2f %.2f %.2f", L, S, SC, V);
|
||||
|
||||
return 0 ;
|
||||
}
|
16
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-8温度转换.c
Executable file
16
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-8温度转换.c
Executable file
@ -0,0 +1,16 @@
|
||||
#include<stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
float C;
|
||||
float F;
|
||||
|
||||
scanf("%f",&F);
|
||||
|
||||
C = 5*( F - 32 ) / 9;
|
||||
|
||||
printf("%.2f",C);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
25
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-9单个字符输入和输出(顺序结构).c
Executable file
25
Test/C/程序设计基础I/实验1--顺序结构程序设计/OJ1-9单个字符输入和输出(顺序结构).c
Executable file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
用getchar()从键盘上输入一个字符,用putchar()打印出来!
|
||||
Input
|
||||
|
||||
从键盘上输入一个字符!
|
||||
Output
|
||||
|
||||
把刚刚输入的字符打印出来!
|
||||
|
||||
*/
|
||||
|
||||
#include<stdio.h>
|
||||
int main ()
|
||||
{
|
||||
int a;
|
||||
|
||||
a = getchar();
|
||||
|
||||
putchar(a);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
50
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-10找中间数.c
Executable file
50
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-10找中间数.c
Executable file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
Description
|
||||
输入三个整数,找出其中的中间数。(这里的中间数指的是大小,不是位置。)
|
||||
|
||||
Input
|
||||
输入3个整数。
|
||||
|
||||
Output
|
||||
输出中间数。
|
||||
|
||||
Sample
|
||||
Input
|
||||
1 2 3
|
||||
Output
|
||||
2
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main ()
|
||||
{
|
||||
int a, b, c, t;
|
||||
|
||||
scanf("%d %d %d", &a, &b, &c);
|
||||
|
||||
if ( a < b )
|
||||
{
|
||||
//交换ab的数值
|
||||
t = a;
|
||||
a = b;
|
||||
b = t;
|
||||
}
|
||||
if ( b < c )
|
||||
{
|
||||
//交换bc的数值
|
||||
t = b;
|
||||
b = c;
|
||||
c = t;
|
||||
}
|
||||
if (b > a)
|
||||
{
|
||||
//交换ac的数值
|
||||
t = b;
|
||||
b = a;
|
||||
a = t;
|
||||
}
|
||||
|
||||
printf ("%d\n", b);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
30
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-11整除.c
Executable file
30
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-11整除.c
Executable file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
Description
|
||||
判断一个数n能否同时被3和5整除。
|
||||
|
||||
Input
|
||||
输入一个正整数n。
|
||||
|
||||
Output
|
||||
如果能够同时被3和5整除,输出Yes,否则输出No。
|
||||
|
||||
Sample
|
||||
Input
|
||||
15
|
||||
Output
|
||||
Yes
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main ()
|
||||
{
|
||||
int a;
|
||||
|
||||
scanf("%d", &a);
|
||||
|
||||
if (( a % 3 == 0) && (a % 5 == 0) )
|
||||
printf("Yes");
|
||||
else
|
||||
printf("No");
|
||||
|
||||
return 0;
|
||||
}
|
29
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-12闰年.c
Executable file
29
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-12闰年.c
Executable file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
Description
|
||||
时间过得真快啊,又要过年了,同时,我们的人生也增长了一年的阅历,又成熟了一些。可是,你注意过今年是不是闰年呢,明年呢?
|
||||
Input
|
||||
只有一个整数year,代表年份。
|
||||
|
||||
Output
|
||||
如果是闰年输出Yes,否则输出No。
|
||||
|
||||
Sample
|
||||
Input
|
||||
2000
|
||||
Output
|
||||
Yes
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main ()
|
||||
{
|
||||
int year;
|
||||
|
||||
scanf("%d", &year);
|
||||
|
||||
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
|
||||
printf("Yes\n");
|
||||
else
|
||||
printf("No\n");
|
||||
|
||||
return 0;
|
||||
}
|
60
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-13C:C++经典程序训练3---模拟计算器.c
Executable file
60
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-13C:C++经典程序训练3---模拟计算器.c
Executable file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
Description
|
||||
简单计算器模拟:输入两个整数和一个运算符,输出运算结果。
|
||||
|
||||
Input
|
||||
第一行输入两个整数,用空格分开;
|
||||
第二行输入一个运算符(+、-、*、/)。
|
||||
所有运算均为整数运算,保证除数不包含0。
|
||||
|
||||
Output
|
||||
输出对两个数运算后的结果。
|
||||
|
||||
Sample
|
||||
Input
|
||||
30 50
|
||||
*
|
||||
Output
|
||||
1500
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main ()
|
||||
{
|
||||
int a, b, sum;
|
||||
char c;
|
||||
|
||||
scanf("%d %d", &a, &b);
|
||||
scanf(" %c", &c);
|
||||
|
||||
if (a != 0 && b != 0)
|
||||
{
|
||||
|
||||
if ('+' == c)
|
||||
{
|
||||
sum = a + b;
|
||||
printf("%d", sum);
|
||||
}
|
||||
|
||||
else if ('-' == c)
|
||||
{
|
||||
sum = a - b;
|
||||
printf("%d", sum);
|
||||
}
|
||||
|
||||
else if ('*' == c)
|
||||
{
|
||||
sum = a * b;
|
||||
printf("%d", sum);
|
||||
}
|
||||
|
||||
else if ('/' == c)
|
||||
{
|
||||
sum = a / b;
|
||||
printf("%d", sum);
|
||||
}
|
||||
}
|
||||
else return 0;
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
42
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-14某年某月的天数.c
Executable file
42
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-14某年某月的天数.c
Executable file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
Description
|
||||
输入三个整数a,b,c。并进行两两相加,最后比较相加和的最大值。
|
||||
Input
|
||||
输入数据包含三个整数,用空格分开。
|
||||
Output
|
||||
输出两两相加后的最大值。
|
||||
Sample
|
||||
Input
|
||||
1 2 3
|
||||
Output
|
||||
5
|
||||
*/
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int y,m,d;
|
||||
scanf("%d\\%d",&y,&m);//输入\时用\\转义
|
||||
switch(m)
|
||||
{
|
||||
case 1:
|
||||
case 3:
|
||||
case 5:
|
||||
case 7:
|
||||
case 8:
|
||||
case 10:
|
||||
case 12:d=31;break;
|
||||
case 4:
|
||||
case 6:
|
||||
case 9:
|
||||
case 11:d=30;break;
|
||||
case 2:
|
||||
if((y%4==0&&y%100!=0)||(y%400==0))
|
||||
d=29;
|
||||
else
|
||||
d=28;
|
||||
}
|
||||
printf("%d\n",d);
|
||||
return 0;
|
||||
}
|
71
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-15C语言实验——输入数字星期,输出英文(switch语句).c
Executable file
71
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-15C语言实验——输入数字星期,输出英文(switch语句).c
Executable file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
从键盘上输入数字星期,然后输出它的英文。
|
||||
其对应关系是:
|
||||
1 Monday
|
||||
2 Tuesday
|
||||
3 Wednesday
|
||||
4 Thursday
|
||||
5 Friday
|
||||
6 Saturday
|
||||
7 Sunday
|
||||
Input
|
||||
|
||||
从键盘输入数字星期,输入数字在1-7之间。
|
||||
Output
|
||||
|
||||
输出该数字对应的英文星期表示。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
2
|
||||
Output
|
||||
|
||||
Tuesday
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main ()
|
||||
{
|
||||
int nu;
|
||||
|
||||
scanf("%d", &nu);
|
||||
|
||||
switch (nu)
|
||||
{
|
||||
case 1:
|
||||
printf("Monday");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
printf("Tuesday");
|
||||
break;
|
||||
|
||||
case 3:
|
||||
printf("Wednesday");
|
||||
break;
|
||||
|
||||
case 4:
|
||||
printf("Thursday");
|
||||
break;
|
||||
|
||||
case 5:
|
||||
printf("Friday");
|
||||
break;
|
||||
|
||||
case 6:
|
||||
printf("Saturday");
|
||||
break;
|
||||
|
||||
case 7:
|
||||
printf("Sunday");
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
40
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-1C语言实验——求绝对值(选择结构).c
Executable file
40
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-1C语言实验——求绝对值(选择结构).c
Executable file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
从键盘输入两个时间点(24小时制),输出两个时间点之间的时间间隔,时间间隔用“小时:分钟:秒”表示。
|
||||
如:3点5分25秒应表示为--03:05:25.假设两个时间在同一天内,时间先后顺序与输入无关。
|
||||
Input
|
||||
|
||||
输入包括两行。
|
||||
第一行为时间点1。
|
||||
第二行为时间点2。
|
||||
Output
|
||||
|
||||
以“小时:分钟:秒”的格式输出时间间隔。
|
||||
格式参看输入输出。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
12:01:12
|
||||
13:09:43
|
||||
Output
|
||||
|
||||
01:08:31
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int a;
|
||||
|
||||
scanf("%d", &a);
|
||||
|
||||
if (a<0)
|
||||
printf("%d", -a);
|
||||
else
|
||||
printf("%d", a);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
99
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-2C语言实验——时间间隔.c
Executable file
99
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-2C语言实验——时间间隔.c
Executable file
@ -0,0 +1,99 @@
|
||||
|
||||
/*
|
||||
Description
|
||||
|
||||
从键盘输入两个时间点(24小时制),输出两个时间点之间的时间间隔,时间间隔用“小时:分钟:秒”表示。
|
||||
如:3点5分25秒应表示为--03:05:25.假设两个时间在同一天内,时间先后顺序与输入无关。
|
||||
Input
|
||||
|
||||
输入包括两行。
|
||||
第一行为时间点1。
|
||||
第二行为时间点2。
|
||||
Output
|
||||
|
||||
以“小时:分钟:秒”的格式输出时间间隔。
|
||||
格式参看输入输出。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
12:01:12
|
||||
13:09:43
|
||||
Output
|
||||
|
||||
01:08:31
|
||||
*/
|
||||
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int a,b,d,e,f,g,i, j, k, s2, m2, h2;
|
||||
char c;
|
||||
|
||||
scanf("%d %c %d %c %d", &a, &c, &b, &c, &d);
|
||||
scanf("%d %c %d %c %d", &e, &c, &f, &c, &g);
|
||||
|
||||
//大小置换
|
||||
if (a < e)
|
||||
{
|
||||
h2 = a;
|
||||
a = e;
|
||||
e = h2;
|
||||
|
||||
m2 = b;
|
||||
b = f;
|
||||
f = m2;
|
||||
|
||||
s2 = d;
|
||||
d = g;
|
||||
g = s2;
|
||||
}
|
||||
else
|
||||
{
|
||||
a = a;
|
||||
b = b;
|
||||
d = d;
|
||||
e = e;
|
||||
f = f;
|
||||
g = g;
|
||||
}
|
||||
|
||||
i = a - e;
|
||||
j = b - f;
|
||||
k = d - g;
|
||||
|
||||
// 秒
|
||||
if (k < 0)
|
||||
{
|
||||
k = 60 + k;
|
||||
j = j - 1;
|
||||
}
|
||||
|
||||
else
|
||||
k = k;
|
||||
// 分
|
||||
if (j < 0)
|
||||
{
|
||||
j = 60 + j;
|
||||
i = i - 1;
|
||||
}
|
||||
|
||||
else if (j >= 60)
|
||||
{
|
||||
j = j - 60;
|
||||
i = i + 1;
|
||||
}
|
||||
else if (j >=0 && j <= 60)
|
||||
j = j;
|
||||
// 时
|
||||
if (i < 0)
|
||||
i = - i;
|
||||
else
|
||||
i = i;
|
||||
|
||||
printf("%02d%c%02d%c%02d", i, c, j, c, k);
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
35
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-3C语言实验——求两个整数之中较大者.c
Executable file
35
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-3C语言实验——求两个整数之中较大者.c
Executable file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
输入两个整数,请编程求其中的较大者。
|
||||
Input
|
||||
|
||||
在一行中输入用空格隔开的两个整数,例如5 9。
|
||||
Output
|
||||
|
||||
输出两个整数之中较大者,输出形式举例:max=9。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
5 9
|
||||
Output
|
||||
|
||||
max=9
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main ()
|
||||
{
|
||||
int a, b;
|
||||
|
||||
scanf("%d %d", &a, &b);
|
||||
|
||||
if (a>b)
|
||||
printf("max=%d", a);
|
||||
else
|
||||
printf("max=%d", b);
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
31
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-4小鑫吃苹果.c
Executable file
31
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-4小鑫吃苹果.c
Executable file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
Description
|
||||
每年平安夜的时候妈妈都会给小鑫邮寄两个大苹果,两个苹果的重量分别为x,y。以前小鑫都是自己默默的吃掉两个大苹果,但是这次小鑫决定要把最重的苹果送给他的女神。可惜他比较笨分不出哪个苹果重哪个苹果轻,所以请你帮他找到最重的苹果,输出最重的重量。
|
||||
|
||||
Input
|
||||
单组输入。
|
||||
两个正整数表示苹果的重量x,y(1 <= (x, y) <= 1000)
|
||||
Output
|
||||
输出两个苹果中最重的重量。
|
||||
Sample
|
||||
Input
|
||||
100 200
|
||||
Output
|
||||
200
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main ()
|
||||
{
|
||||
int x, y;
|
||||
|
||||
scanf("%d %d", &x, &y);
|
||||
|
||||
if (x>y)
|
||||
printf("%d", x);
|
||||
else
|
||||
printf("%d", y);
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
37
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-5小鑫の日常系列故事(一)——判断对错.c
Executable file
37
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-5小鑫の日常系列故事(一)——判断对错.c
Executable file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
话说小鑫可是一个奇人,在他刚出生的时候,就能口算出1000000以内的加法。因为他有这样一项能力,他的父母专门雇佣了一位可爱的保姆姐姐(内部消息不超过二十岁哦)来训练他。可是这位保姆姐姐有时候脑袋会秀逗一下,如果被小鑫的父母发现了可是要丢掉工作的。于是她找到了身为程序员的你,你能用你的双手来帮助他解决问题么?
|
||||
Input
|
||||
|
||||
输入有两行,第一行为两个整数a,b(a,b>0)。第二行为一个数,为小鑫对于a+b口算出的答案。
|
||||
Output
|
||||
|
||||
输出为一行。判断小鑫给出的答案是否正确,如果是输出“YES”,否则输出“NO”。(输出不包括引号)
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
1 2
|
||||
3
|
||||
Output
|
||||
|
||||
YES
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main ()
|
||||
{
|
||||
int a, b, c;
|
||||
|
||||
scanf("%d %d %d", &a, &b, &c);
|
||||
|
||||
|
||||
if (c == a + b)
|
||||
printf("YES\n");
|
||||
else
|
||||
printf("NO\n");
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
32
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-6小鑫追女神.c
Executable file
32
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-6小鑫追女神.c
Executable file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
Description
|
||||
小鑫长得比较丑,但还是对女神垂涎不止,小鑫向女神表白了。女神毕竟是女神,女神的世界里,只有0和1。0代表女神拒绝了他,1代表女神接受了他。现在你需要判断女神到底是接受了他还是拒绝了他。若接受,输出“I like you”(不包括引号),若拒绝,输出“He he”(不包括引号)。
|
||||
|
||||
Input
|
||||
单组输入。
|
||||
输入只有一个数,保证只有0或1。
|
||||
Output
|
||||
输出女神对小鑫的态度,“I like you”(不包括引号)或“He he”(不包括引号)
|
||||
Sample
|
||||
Input
|
||||
0
|
||||
Output
|
||||
He he
|
||||
Hint
|
||||
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int a;
|
||||
|
||||
scanf("%d", &a);
|
||||
|
||||
if (a == 1)
|
||||
printf("I like you\n");
|
||||
else if (a == 0)
|
||||
printf("He he\n");
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
48
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-7求三个整数的最大值.c
Executable file
48
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-7求三个整数的最大值.c
Executable file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
Description
|
||||
请编写程序,输入三个整数,求出其中的最大值输出。
|
||||
|
||||
Input
|
||||
在一行上输入三个整数,整数间用逗号分隔。
|
||||
|
||||
Output
|
||||
输出三个数中的最大值。
|
||||
|
||||
Sample
|
||||
Input
|
||||
5,7,9
|
||||
Output
|
||||
max=9
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main ()
|
||||
{
|
||||
int a,b,c,t,max;
|
||||
scanf("%d,%d,%d",&a,&b,&c);
|
||||
if(a>b)
|
||||
{
|
||||
t=a;
|
||||
a=b;
|
||||
b=t;
|
||||
|
||||
}
|
||||
if(a>c)
|
||||
{
|
||||
t=a;
|
||||
a=c;
|
||||
c=t;
|
||||
|
||||
}
|
||||
if(b>c)
|
||||
{
|
||||
t=b;
|
||||
b=c;
|
||||
c=t;
|
||||
|
||||
}
|
||||
max=c;
|
||||
|
||||
printf("max=%d\n",max);
|
||||
return 0;
|
||||
|
||||
}
|
57
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-8相加和最大值.c
Executable file
57
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-8相加和最大值.c
Executable file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
Description
|
||||
输入三个整数a,b,c。并进行两两相加,最后比较相加和的最大值。
|
||||
Input
|
||||
输入数据包含三个整数,用空格分开。
|
||||
Output
|
||||
输出两两相加后的最大值。
|
||||
Sample
|
||||
Input
|
||||
1 2 3
|
||||
Output
|
||||
5
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
|
||||
int a, b, c, d, e, f, t, max;
|
||||
|
||||
scanf("%d %d %d",&d,&e,&f);
|
||||
|
||||
a = d + e;
|
||||
b = d + f;
|
||||
c = e + f;
|
||||
|
||||
|
||||
|
||||
if(a>b)
|
||||
{
|
||||
t=a;
|
||||
a=b;
|
||||
b=t;
|
||||
|
||||
}
|
||||
if(a>c)
|
||||
{
|
||||
t=a;
|
||||
a=c;
|
||||
c=t;
|
||||
|
||||
}
|
||||
if(b>c)
|
||||
{
|
||||
t=b;
|
||||
b=c;
|
||||
c=t;
|
||||
|
||||
}
|
||||
max=c;
|
||||
|
||||
printf("%d\n",max);
|
||||
return 0;
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
50
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-9从大到小输出a、b、c(选择结构).c
Executable file
50
Test/C/程序设计基础I/实验2--选择结构程序设计/OJ2-9从大到小输出a、b、c(选择结构).c
Executable file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
Description
|
||||
从键盘输入三个整数a、b、c,要求将输出的数据按从大到小排序后输出。
|
||||
|
||||
Input
|
||||
从键盘上输入三个整数a、b、c,每个整数之间用空格分开。
|
||||
|
||||
Output
|
||||
从大到小顺序输出a、b、c的值。
|
||||
|
||||
Sample
|
||||
Input
|
||||
4 3 5
|
||||
Output
|
||||
5 4 3
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main ()
|
||||
{
|
||||
int a, b, c, t;
|
||||
|
||||
scanf("%d %d %d", &a, &b, &c);
|
||||
|
||||
if ( a < b )
|
||||
{
|
||||
//交换ab的数值
|
||||
t = a;
|
||||
a = b;
|
||||
b = t;
|
||||
}
|
||||
if ( b < c )
|
||||
{
|
||||
//交换bc的数值
|
||||
t = b;
|
||||
b = c;
|
||||
c = t;
|
||||
}
|
||||
if (b > a)
|
||||
{
|
||||
//交换ac的数值
|
||||
t = b;
|
||||
b = a;
|
||||
a = t;
|
||||
}
|
||||
|
||||
printf ("%d %d %d\n", a, b, c);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
38
Test/C/程序设计基础I/实验3--while 循环结构程序设计/A+B for Input-Output Practice (I).c
Executable file
38
Test/C/程序设计基础I/实验3--while 循环结构程序设计/A+B for Input-Output Practice (I).c
Executable file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
Your task is to Calculate a + b.
|
||||
|
||||
Too easy?! Of course! I specially designed the problem for acm beginners.
|
||||
|
||||
You must have found that some problems have the same titles with this one, yes, all these problems were designed for the same aim
|
||||
Input
|
||||
|
||||
The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.
|
||||
Output
|
||||
|
||||
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
1 5
|
||||
10 20
|
||||
Output
|
||||
|
||||
6
|
||||
30
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int a,b;
|
||||
|
||||
while(scanf("%d %d", &a,&b) != EOF)
|
||||
{
|
||||
printf("%d\n",a+b);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
37
Test/C/程序设计基础I/实验3--while 循环结构程序设计/A+B for Input-Output Practice (III).c
Executable file
37
Test/C/程序设计基础I/实验3--while 循环结构程序设计/A+B for Input-Output Practice (III).c
Executable file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
Your task is to Calculate a + b.
|
||||
Input
|
||||
|
||||
Inputcontains multiple test cases. Each test case contains a pair of integers a and b, one pair of integers per line. A test case containing 0 0 terminates the input and this test case is not to be processed.
|
||||
Output
|
||||
|
||||
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
1 5
|
||||
10 20
|
||||
0 0
|
||||
Output
|
||||
|
||||
6
|
||||
30
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int a,b;
|
||||
|
||||
while(scanf("%d %d", &a,&b) !=EOF)
|
||||
{
|
||||
if (a!=0||b!=0)
|
||||
printf("%d\n",a+b);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
36
Test/C/程序设计基础I/实验3--while 循环结构程序设计/A+B for Input-Output Practice (VII).c
Executable file
36
Test/C/程序设计基础I/实验3--while 循环结构程序设计/A+B for Input-Output Practice (VII).c
Executable file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
Your task is to Calculate a + b.
|
||||
Input
|
||||
|
||||
The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.
|
||||
Output
|
||||
|
||||
For each pair of input integers a and b you should output the sum of a and b, and followed by a blank line.
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
1 5
|
||||
10 20
|
||||
Output
|
||||
|
||||
6
|
||||
|
||||
30
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int a,b;
|
||||
|
||||
while(scanf("%d %d", &a,&b) !=EOF)
|
||||
{
|
||||
printf("%d",a+b);
|
||||
printf("\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
42
Test/C/程序设计基础I/实验3--while 循环结构程序设计/N 计算球体积.c
Executable file
42
Test/C/程序设计基础I/实验3--while 循环结构程序设计/N 计算球体积.c
Executable file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
根据输入的半径值,计算球的体积。
|
||||
Input
|
||||
|
||||
输入数据有多组,每组占一行,每行包括一个实数,表示球的半径。
|
||||
Output
|
||||
|
||||
输出对应的球的体积,对于每组输入数据,输出一行,计算结果保留三位小数。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
1
|
||||
1.5
|
||||
Output
|
||||
|
||||
4.189
|
||||
14.137
|
||||
Hint
|
||||
|
||||
已知 PI = 3.1415927
|
||||
|
||||
#define PI 3.1415927
|
||||
*/
|
||||
#include<stdio.h>
|
||||
#define PI 3.1415927
|
||||
|
||||
int main()
|
||||
{
|
||||
double r;
|
||||
double v=0;
|
||||
|
||||
while (scanf("%lf", &r)!=EOF)
|
||||
{
|
||||
v = (4.0*PI*r*r*r)/3.0;
|
||||
printf("%.3lf\n", v);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
40
Test/C/程序设计基础I/实验3--while 循环结构程序设计/OJ3-10计算球体积.c
Executable file
40
Test/C/程序设计基础I/实验3--while 循环结构程序设计/OJ3-10计算球体积.c
Executable file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
根据输入的半径值,计算球的体积。
|
||||
Input
|
||||
|
||||
输入数据有多组,每组占一行,每行包括一个实数,表示球的半径。
|
||||
Output
|
||||
|
||||
输出对应的球的体积,对于每组输入数据,输出一行,计算结果保留三位小数。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
1
|
||||
1.5
|
||||
Output
|
||||
|
||||
4.189
|
||||
14.137
|
||||
Hint
|
||||
|
||||
#define PI 3.1415927
|
||||
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#define pi 3.1415927
|
||||
int main ()
|
||||
{
|
||||
double r1, v1;
|
||||
|
||||
while (scanf("%lf", &r1) != EOF)
|
||||
{
|
||||
v1 = (pi * r1 * r1 * r1) * (double)4/3;
|
||||
|
||||
printf("%.3lf\n", v1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
36
Test/C/程序设计基础I/实验3--while 循环结构程序设计/OJ3-11洗衣服.c
Executable file
36
Test/C/程序设计基础I/实验3--while 循环结构程序设计/OJ3-11洗衣服.c
Executable file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
X是一个勤劳的小孩,总是会帮助大人做家务。现在他想知道对于一根长为L的绳子能晾开多少件宽为W的衣服,显然这些衣服不能相互叠压。
|
||||
Input
|
||||
|
||||
多组输入。
|
||||
每组输入两个整数L,W。
|
||||
Output
|
||||
|
||||
输出答案。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
10 5
|
||||
10 4
|
||||
Output
|
||||
|
||||
2
|
||||
2
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main ()
|
||||
{
|
||||
|
||||
int l, w, n;
|
||||
|
||||
while (scanf("%d%d", &l, &w) != EOF)
|
||||
{
|
||||
n = l/w;
|
||||
printf("%d\n", n);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
106
Test/C/程序设计基础I/实验3--while 循环结构程序设计/OJ3-12压岁钱-整数判断(存疑).c
Executable file
106
Test/C/程序设计基础I/实验3--while 循环结构程序设计/OJ3-12压岁钱-整数判断(存疑).c
Executable file
@ -0,0 +1,106 @@
|
||||
/*
|
||||
|
||||
Description
|
||||
|
||||
SuShan过年要给孩子们发压岁钱喽,由于家里孩子很多,这可急坏了SuShan。你肯定以为她在担心钱不够,那你错了,她可是个有钱人儿,不差钱儿。她担心的是每个人分多少从而保证公平。
|
||||
SuShan从瑞士银行提出1000000来给孩子们分,由于来的孩子的数目不确定,所以SuShan希望你能帮他计算一下每个孩子给多少钱,从而保证每个孩子得到的都是整数。
|
||||
Input
|
||||
|
||||
输入有多组数据,第一行 T 代表数据的组数。
|
||||
接下来有 T 行,每行一个整数 N,代表孩子的数目,1<= N <= 10000000。
|
||||
|
||||
|
||||
Output
|
||||
|
||||
只有一行。如果能够分给每个孩子相同数目的压岁钱,且都是整数,则输出每个孩子得到的钱数。否则输出No。
|
||||
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
3
|
||||
1
|
||||
2
|
||||
3
|
||||
Output
|
||||
|
||||
1000000
|
||||
500000
|
||||
No
|
||||
|
||||
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int n, x;
|
||||
double a;
|
||||
int money = 10000000;
|
||||
|
||||
scanf("%d", &x);
|
||||
|
||||
while (x--)
|
||||
{
|
||||
scanf("%d", &n);
|
||||
|
||||
if (1 <= n && money >=n)
|
||||
{
|
||||
a = (double)money / n;
|
||||
if (a != (int)a)
|
||||
{
|
||||
printf("No\n");
|
||||
}
|
||||
else
|
||||
printf("%.0lf\n", a);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int T, N,c,a;
|
||||
T= 0;
|
||||
scanf("%d",&T);
|
||||
|
||||
while (T>0)
|
||||
{
|
||||
scanf("%d",&N);
|
||||
a = 1000000%N;
|
||||
c = 1000000/N;
|
||||
if (a==0)
|
||||
printf("%d\n",c);
|
||||
else
|
||||
printf("NO\n");
|
||||
T=T-1;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int money=1000000;
|
||||
int i;
|
||||
int n;
|
||||
scanf("%d",&i);
|
||||
while(i--)
|
||||
{
|
||||
scanf("%d",&n);
|
||||
if (money % n == 0)
|
||||
printf("%d\n",money/n);
|
||||
else
|
||||
printf("No\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
42
Test/C/程序设计基础I/实验3--while 循环结构程序设计/OJ3-1数列求和3.c
Executable file
42
Test/C/程序设计基础I/实验3--while 循环结构程序设计/OJ3-1数列求和3.c
Executable file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
|
||||
Description
|
||||
|
||||
正整数序列是指从1开始的序列,例如{1,2,3,4,......}
|
||||
|
||||
给定一个整数 n,现在请你求出正整数序列 1 - n 的和。
|
||||
Input
|
||||
|
||||
输入一个整数 n 。(1 <= n <= 1000)
|
||||
Output
|
||||
|
||||
输出一个整数,即为正确答案。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
2
|
||||
Output
|
||||
|
||||
3
|
||||
|
||||
*/
|
||||
|
||||
#include<stdio.h>
|
||||
int main ()
|
||||
{
|
||||
int n, i;
|
||||
int sum = 0;
|
||||
|
||||
scanf("%d", &n);
|
||||
i = 1;
|
||||
while (i<=n)
|
||||
{
|
||||
sum = sum + i;
|
||||
|
||||
++i;
|
||||
}
|
||||
printf("%d\n",sum);
|
||||
|
||||
return 0;
|
||||
}
|
34
Test/C/程序设计基础I/实验3--while 循环结构程序设计/OJ3-2数位数.c
Executable file
34
Test/C/程序设计基础I/实验3--while 循环结构程序设计/OJ3-2数位数.c
Executable file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
|
||||
Description
|
||||
|
||||
输入一个正整数N,求出N^3的各位数字的立方和。
|
||||
Input
|
||||
|
||||
输入N的值。N<=1024
|
||||
Output
|
||||
|
||||
问题描述中所要求的数值。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
3
|
||||
Output
|
||||
|
||||
351
|
||||
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int n, s;
|
||||
|
||||
scanf("%d", &n);
|
||||
|
||||
s = n * n * n;
|
||||
|
||||
printf("%d", s);
|
||||
|
||||
return 0;
|
||||
}
|
39
Test/C/程序设计基础I/实验3--while 循环结构程序设计/OJ3-3N^3问题.c
Executable file
39
Test/C/程序设计基础I/实验3--while 循环结构程序设计/OJ3-3N^3问题.c
Executable file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
|
||||
Description
|
||||
|
||||
输入一个正整数N,求出N^3的各位数字的立方和。
|
||||
Input
|
||||
|
||||
输入N的值。N<=1024
|
||||
Output
|
||||
|
||||
问题描述中所要求的数值。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
3
|
||||
Output
|
||||
|
||||
351
|
||||
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int n, c, a, sum=0;
|
||||
|
||||
scanf("%d", &n);
|
||||
|
||||
n = n * n * n;
|
||||
|
||||
while(n>0)
|
||||
{
|
||||
a = n % 10;
|
||||
n = n / 10;
|
||||
c = a * a * a;
|
||||
sum = sum + c;
|
||||
}
|
||||
printf("%d\n",sum);
|
||||
}
|
35
Test/C/程序设计基础I/实验3--while 循环结构程序设计/OJ3-4小树快长高.c
Executable file
35
Test/C/程序设计基础I/实验3--while 循环结构程序设计/OJ3-4小树快长高.c
Executable file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
|
||||
Description
|
||||
|
||||
小明在植树节种了一棵小树,小明非常关心小树,每天都给小树浇水,盼望着小树快快长高。他知道小树现在有 n cm,每天长高k cm,他想知道多少天小树可以长到m cm。
|
||||
Input
|
||||
|
||||
输入三个整数 n, m, k。 ( 0 <= n<= 10000, 0 <= m <= 10000,0 <= k <= 10000)
|
||||
Output
|
||||
|
||||
输出一个整数,即需要的天数。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
100 200 5
|
||||
Output
|
||||
|
||||
20
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int n,m,k,t=0;
|
||||
scanf("%d %d %d",&n,&m,&k);
|
||||
while(m>n)
|
||||
{
|
||||
m = m - k;
|
||||
t++;
|
||||
}
|
||||
printf("%d\n",t);
|
||||
return 0;
|
||||
}
|
46
Test/C/程序设计基础I/实验3--while 循环结构程序设计/OJ3-5偶数数位求和.c
Executable file
46
Test/C/程序设计基础I/实验3--while 循环结构程序设计/OJ3-5偶数数位求和.c
Executable file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
|
||||
Description
|
||||
|
||||
给定一个整数,请求出这个整数所有数位中是偶数的数位的和。例如,对于12436546,那么答案就是 2 + 4 + 6 + 4 + 6 。
|
||||
Input
|
||||
|
||||
输入一个数 n 。 (0 <= n <= 2147483647)
|
||||
Output
|
||||
|
||||
输出 n 的所有偶数数位的和。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
6768
|
||||
Output
|
||||
|
||||
20
|
||||
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main ()
|
||||
{
|
||||
int n, i, a, j;
|
||||
|
||||
scanf("%d", &n);
|
||||
|
||||
i = 0;
|
||||
while (n > 0)
|
||||
{
|
||||
a = n %10;
|
||||
n = n / 10;
|
||||
j = a %2;
|
||||
|
||||
if (j == 0)
|
||||
i = i + a;
|
||||
|
||||
else
|
||||
n = n;
|
||||
|
||||
}
|
||||
printf("%d\n", i);
|
||||
|
||||
return 0;
|
||||
}
|
57
Test/C/程序设计基础I/实验3--while 循环结构程序设计/OJ3-6小粉的难题.c
Executable file
57
Test/C/程序设计基础I/实验3--while 循环结构程序设计/OJ3-6小粉的难题.c
Executable file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
|
||||
Description
|
||||
|
||||
小粉和哈士奇是好朋友,一天,哈士奇去找小粉玩,但小粉还没做完功课。粉妈妈说只有做完功课才能出门,这可急坏了小粉,于是小粉让哈士奇和他一块做功课。其中有一道题是这样的:
|
||||
|
||||
给出一个正整数 n 和数字 m ( m 取值范围[0,9]中的一个数字),求 m 在 n 中出现的次数。
|
||||
|
||||
比如 n = 2122345 , m = 2,答案就是 3 ,因为 2 在 2122345 中出现了三次。
|
||||
|
||||
哈士奇的数学不好,为了尽快做完功课,他找到了会编程的你,请你编写程序解决这个问题。
|
||||
Input
|
||||
|
||||
输入只有一行,包含两个空格分开的整数 n 和 m 。(0 <= m <= 9,1 <= n <= 2147483647)
|
||||
Output
|
||||
|
||||
输出一个数字,表示 m 在 n 中 出现的次数。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
2122345 2
|
||||
Output
|
||||
|
||||
3
|
||||
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int n, m, a, i;
|
||||
|
||||
scanf("%d %d", &n, &m);
|
||||
|
||||
if ((0 <= m && m <= 9)&&(1 <= n && n <= 214748364))
|
||||
{
|
||||
i = 0;
|
||||
while (n > 0)
|
||||
{
|
||||
a = n%10;
|
||||
n = n/10;
|
||||
|
||||
if (a == m)
|
||||
{
|
||||
++i;
|
||||
}
|
||||
else
|
||||
n = n;
|
||||
}
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
|
||||
printf("%d\n", i);
|
||||
|
||||
return 0;
|
||||
}
|
42
Test/C/程序设计基础I/实验3--while 循环结构程序设计/OJ3-7小金问呀问不会问题.c
Executable file
42
Test/C/程序设计基础I/实验3--while 循环结构程序设计/OJ3-7小金问呀问不会问题.c
Executable file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
|
||||
Description
|
||||
|
||||
众所周知,C语言的学习是我们程序设计基础的重点和主要内容。
|
||||
小金在班里是一个爱学习的好孩子,但是他的编程能力却有点差,不过他坚信自己一定可以进步并追上其他同学。
|
||||
|
||||
Input
|
||||
|
||||
多组输入。
|
||||
从键盘读入一个整数n,如果n >= 0代表小金考试进步了,如果n < 0代表小金退步了。
|
||||
Output
|
||||
|
||||
如果小明进步了输出”Yes”,反之输出”No”。输出不包括引号,输入输出各占一行,保证数据合法。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
100
|
||||
-100
|
||||
Output
|
||||
|
||||
Yes
|
||||
No
|
||||
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
|
||||
while(scanf("%d", &n) != EOF)
|
||||
{
|
||||
if (n >= 0)
|
||||
printf("Yes\n");
|
||||
else
|
||||
printf("No\n");
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
48
Test/C/程序设计基础I/实验3--while 循环结构程序设计/OJ3-8优越数.c
Executable file
48
Test/C/程序设计基础I/实验3--while 循环结构程序设计/OJ3-8优越数.c
Executable file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
|
||||
Description
|
||||
|
||||
|
||||
给定3个数,如果有两个数大于他们的平均数则称这组数为优越数。(定义纯属虚构)
|
||||
Input
|
||||
|
||||
|
||||
输入第一行是一个整数: 表示测试数据的组数。
|
||||
对于每组测试数据,仅一行3个整数。
|
||||
Output
|
||||
|
||||
|
||||
对于每组输入数据输出一行,判断它是否为一组优越数,如果是输出“Yes”(输出不包括引号),否则输出“No”。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
2
|
||||
1 2 3
|
||||
1 4 4
|
||||
Output
|
||||
|
||||
No
|
||||
Yes
|
||||
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main ()
|
||||
{
|
||||
int a, n1, n2, n3;
|
||||
int e, s;
|
||||
|
||||
scanf("%d", &a);
|
||||
|
||||
while (scanf("%d %d %d", &n1, &n2, &n3)!= EOF)
|
||||
{
|
||||
s = n1 + n2 + n3;
|
||||
e = (float)s / 3;
|
||||
if ((n1 > e && n2 > e) || (n1 > e && n3 >e)||(n2 > e && n3 >e))
|
||||
printf("Yes\n");
|
||||
else
|
||||
printf("No\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
55
Test/C/程序设计基础I/实验3--while 循环结构程序设计/OJ3-9分段函数求值.c
Executable file
55
Test/C/程序设计基础I/实验3--while 循环结构程序设计/OJ3-9分段函数求值.c
Executable file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
|
||||
Description
|
||||
|
||||
有如下分段函数
|
||||
F(x) = x^2 + 1 当x> 0时;
|
||||
F(x) = -x 当x<0时;
|
||||
F(x) = 100.0 当x=0时;
|
||||
编程根据输入的不同x(x为实数),输出其对应的函数值
|
||||
Input
|
||||
|
||||
多组输入,每组一个实数x。处理到文件结束。
|
||||
Output
|
||||
|
||||
对于每组输入x,输出其对应的F(x),每组一行,结果保留1位小数。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
8.00
|
||||
-5.0
|
||||
Output
|
||||
|
||||
65.0
|
||||
5.0
|
||||
|
||||
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main ()
|
||||
{
|
||||
double x;
|
||||
|
||||
while (scanf("%lf", &x) != EOF)
|
||||
{
|
||||
if (0 < x )
|
||||
{
|
||||
x = x * x +1;
|
||||
printf("%.1lf\n", x);
|
||||
}
|
||||
else if (0 > x)
|
||||
{
|
||||
x = -x;
|
||||
printf("%.1lf\n", x);
|
||||
}
|
||||
else
|
||||
{
|
||||
x = 100;
|
||||
printf("%.1lf\n", x);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
36
Test/C/程序设计基础I/实验4--for循环结构程序设计/A A+B for Input-Output Practice (II).c
Executable file
36
Test/C/程序设计基础I/实验4--for循环结构程序设计/A A+B for Input-Output Practice (II).c
Executable file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
Your task is to Calculate a + b.
|
||||
Input
|
||||
|
||||
Your task is to Calculate a + b.
|
||||
Output
|
||||
|
||||
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
2
|
||||
1 5
|
||||
10 20
|
||||
Output
|
||||
|
||||
6
|
||||
30
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int a, b, sum, i;
|
||||
|
||||
for (scanf("%d", &i); scanf("%d %d", &a, &b)!=EOF; i--)
|
||||
{
|
||||
sum = a+b;
|
||||
printf("%d\n", sum);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
43
Test/C/程序设计基础I/实验4--for循环结构程序设计/G 简单计算.c
Executable file
43
Test/C/程序设计基础I/实验4--for循环结构程序设计/G 简单计算.c
Executable file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
接受从键盘输入的N个整数,输出其中的最大值、最小值和平均值(平均值为整除的商)。
|
||||
|
||||
Input
|
||||
|
||||
第一行一个正整数N(N<=100);
|
||||
第二行有N个用空格隔开的整数Ti (1 <= i <= N, 0 <= Ti <= 10000000)
|
||||
Output
|
||||
|
||||
三个有空格隔开的整数分别为最大值、最小值和平均值,其中平均值为整除的商。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
5
|
||||
1 2 3 5 4
|
||||
Output
|
||||
|
||||
5 1 3
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int n=0;
|
||||
long long int max=0,min=10000000,sum=0,num=0,average;
|
||||
int i=1;
|
||||
scanf("%d",&n);
|
||||
for(i=1;i<=n;i++)
|
||||
{
|
||||
scanf("%lld",&num);
|
||||
if(num>max)
|
||||
max=num;
|
||||
if(min>num)
|
||||
min=num;
|
||||
sum=sum + num;
|
||||
}
|
||||
average=sum/n;
|
||||
printf("%lld %lld %lld",max,min,average);
|
||||
return 0;
|
||||
|
||||
}
|
61
Test/C/程序设计基础I/实验4--for循环结构程序设计/H C:C++训练1---最大公约数与最小公倍数.c
Executable file
61
Test/C/程序设计基础I/实验4--for循环结构程序设计/H C:C++训练1---最大公约数与最小公倍数.c
Executable file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
输入两个正整数,求它们的最大公约数与最小公倍数。
|
||||
Input
|
||||
|
||||
输入两个正整数,两个整数之间用空格分开。
|
||||
|
||||
数据保证在 int 范围内。
|
||||
Output
|
||||
|
||||
第一行输出最大公约数;
|
||||
第二行输出最小公倍数。
|
||||
|
||||
答案保证在 int 范围内。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
64 48
|
||||
Output
|
||||
|
||||
16
|
||||
192
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int a,b,i,temp;
|
||||
int max,min;
|
||||
|
||||
scanf("%d %d",&a, &b);
|
||||
if (b>a)
|
||||
{
|
||||
temp=a;
|
||||
a=b;
|
||||
b=temp;
|
||||
}
|
||||
else
|
||||
{
|
||||
a=a;
|
||||
b=b;
|
||||
}
|
||||
i=a;
|
||||
while(i>0)//最大公因数
|
||||
{
|
||||
if ((a%i==0)&&(b%i==0))
|
||||
{
|
||||
// printf("%d\n",i);
|
||||
min=i;
|
||||
break;
|
||||
}
|
||||
else
|
||||
i--;
|
||||
}
|
||||
//最小公倍数是两数乘积除以最大公约数
|
||||
max=a*b/min;
|
||||
printf("%d\n%d\n",min, max);
|
||||
return 0;
|
||||
}
|
||||
|
61
Test/C/程序设计基础I/实验4--for循环结构程序设计/I C语言实验——判断素数(循环结构).c
Executable file
61
Test/C/程序设计基础I/实验4--for循环结构程序设计/I C语言实验——判断素数(循环结构).c
Executable file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
从键盘上输入任意一个正整数,然后判断该数是否为素数。
|
||||
如果是素数则输出"This is a prime."
|
||||
否则输出“This is not a prime.”
|
||||
Input
|
||||
|
||||
输入任意一个正整数n(1 <= n <= 1000000)。
|
||||
Output
|
||||
|
||||
判断n是否为素数,并输出判断结果:
|
||||
如果n是素数则输出"This is a prime."
|
||||
否则输出“This is not a prime.”
|
||||
|
||||
特别提醒:请注意对1的判定,1不是素数。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
3
|
||||
Output
|
||||
|
||||
This is a prime.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int a,i,b,c=0;
|
||||
scanf("%d",&a);
|
||||
if (1==a)
|
||||
{
|
||||
printf("This is not a prime.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i=2; i<a; i++)
|
||||
{
|
||||
b= a % i;
|
||||
if (b==0)
|
||||
{
|
||||
c++;
|
||||
}
|
||||
else
|
||||
{
|
||||
c=c;
|
||||
}
|
||||
}
|
||||
if (0==c)
|
||||
{
|
||||
printf("This is a prime.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("This is not a prime.\n");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
48
Test/C/程序设计基础I/实验4--for循环结构程序设计/J 求绝对值最大值.c
Executable file
48
Test/C/程序设计基础I/实验4--for循环结构程序设计/J 求绝对值最大值.c
Executable file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
求n个整数中的绝对值最大的数。
|
||||
Input
|
||||
|
||||
输入数据有2行,第一行为n,第二行是n个整数。
|
||||
Output
|
||||
|
||||
输出n个整数中绝对值最大的数。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
5
|
||||
-1 2 3 4 -5
|
||||
Output
|
||||
|
||||
-5
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int n=0,t = 0;
|
||||
int max = 0,num=0,temp = 0;
|
||||
int i=1;
|
||||
scanf("%d",&n);
|
||||
for(i=1;i<=n;i++)
|
||||
{
|
||||
scanf("%d",&num);
|
||||
if (num<0)
|
||||
{
|
||||
temp=-num;
|
||||
}
|
||||
else
|
||||
{
|
||||
temp=num;
|
||||
}
|
||||
if(temp>max)
|
||||
{
|
||||
max=temp;
|
||||
t=num;
|
||||
}
|
||||
}
|
||||
printf("%d\n",t);
|
||||
return 0;
|
||||
|
||||
}
|
37
Test/C/程序设计基础I/实验4--for循环结构程序设计/K C语言实验——圆周率.c
Executable file
37
Test/C/程序设计基础I/实验4--for循环结构程序设计/K C语言实验——圆周率.c
Executable file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
输入n值,并利用下列格里高里公式计算并输出圆周率:
|
||||
|
||||
Input
|
||||
|
||||
输入公式中的n值。
|
||||
Output
|
||||
|
||||
输出圆周率,保留5位小数。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
1
|
||||
Output
|
||||
|
||||
2.66667
|
||||
*/
|
||||
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int n = 0,i;
|
||||
double pi = 0.0;
|
||||
|
||||
scanf("%d",&n);
|
||||
|
||||
for (i=1; i<=n; i++)
|
||||
{
|
||||
pi=pi+(1.0/(4*i-3));
|
||||
pi=pi-(1.0/(4*i-1));
|
||||
}
|
||||
printf("%.5lf\n",4*pi);
|
||||
return 0;
|
||||
}
|
27
Test/C/程序设计基础I/实验4--for循环结构程序设计/L 小鑫の日常系列故事(五)——卡片游戏.c
Executable file
27
Test/C/程序设计基础I/实验4--for循环结构程序设计/L 小鑫の日常系列故事(五)——卡片游戏.c
Executable file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
小狗对小猫说:你猜猜我的口袋里有几块糖?小猫说:猜对了你给我吃吗?小狗点点头:嗯,猜对了两块都给你!小猫咽了咽口水说:我猜五块!然后,小狗笑着把糖放到小猫手里,说:我还欠你三块。
|
||||
既然小猫这么喜欢吃糖,小狗决定每天都给小猫几块糖,但是呢,不能每天都给相同块数的糖,那样就太单调了。于是,第一天小狗给小猫1*1=1块,第二天2*2=4块……第 n 天给的糖数为 n*n 。现在已知小狗家共有 N 块糖,你需要帮他计算下这些糖最多可以给小猫几天?
|
||||
Input
|
||||
|
||||
输入只有一个整数 N (0 <= N <= 10000)。
|
||||
Output
|
||||
|
||||
输出对应的天数。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
15
|
||||
Output
|
||||
|
||||
3
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int
|
||||
|
||||
return 0;
|
||||
}
|
43
Test/C/程序设计基础I/实验4--for循环结构程序设计/M 猜糖块.c
Executable file
43
Test/C/程序设计基础I/实验4--for循环结构程序设计/M 猜糖块.c
Executable file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
小狗对小猫说:你猜猜我的口袋里有几块糖?小猫说:猜对了你给我吃吗?小狗点点头:嗯,猜对了两块都给你!小猫咽了咽口水说:我猜五块!然后,小狗笑着把糖放到小猫手里,说:我还欠你三块。
|
||||
既然小猫这么喜欢吃糖,小狗决定每天都给小猫几块糖,但是呢,不能每天都给相同块数的糖,那样就太单调了。于是,第一天小狗给小猫1*1=1块,第二天2*2=4块……第 n 天给的糖数为 n*n 。现在已知小狗家共有 N 块糖,你需要帮他计算下这些糖最多可以给小猫几天?
|
||||
Input
|
||||
|
||||
输入只有一个整数 N (0 <= N <= 10000)。
|
||||
Output
|
||||
|
||||
输出对应的天数。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
15
|
||||
Output
|
||||
|
||||
3
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int n,i,sum,d=0;
|
||||
|
||||
scanf("%d",&n);
|
||||
|
||||
for (i=1;n>0; i++)
|
||||
{
|
||||
sum=i*i;
|
||||
n=n-sum;
|
||||
if (n<0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
d=d+1;
|
||||
|
||||
|
||||
}
|
||||
printf("%d\n",d);
|
||||
|
||||
return 0;
|
||||
}
|
40
Test/C/程序设计基础I/实验4--for循环结构程序设计/N C语言实验——分数序列.c
Executable file
40
Test/C/程序设计基础I/实验4--for循环结构程序设计/N C语言实验——分数序列.c
Executable file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
有一个分数序列:2/1, 3/2, 5/3, 8/5, 13/8, …编写程序求出这个序列的前n项之和。
|
||||
Input
|
||||
|
||||
输入只有一个正整数n,1≤n≤10。
|
||||
Output
|
||||
|
||||
输出该序列前n项和,结果保留小数后6位。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
3
|
||||
Output
|
||||
|
||||
5.166667
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int x=1,y=2,n = 0,i,t;
|
||||
double sum=0.0;
|
||||
|
||||
scanf("%d", &n);
|
||||
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
sum= sum+(double)y/x;
|
||||
t = y;
|
||||
y = x+y;
|
||||
x=t;
|
||||
|
||||
}
|
||||
|
||||
printf("%.6lf\n",sum);
|
||||
|
||||
return 0;
|
||||
}
|
79
Test/C/程序设计基础I/实验4--for循环结构程序设计/O 期末考试之分等级.c
Executable file
79
Test/C/程序设计基础I/实验4--for循环结构程序设计/O 期末考试之分等级.c
Executable file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
期末考试结束了,老师想要根据学生们的成绩划分出等级。共有5个等级A,B,C,D和E。
|
||||
划分方法如下,90分(含90)以上的为A,80~90(含80)间的为B,70~80(含70)间的为C,
|
||||
60~70(含60)的为D,不及格的为E。
|
||||
根据输入的成绩,编程输出各个级别段人数。
|
||||
|
||||
Input
|
||||
|
||||
输入第一行包含一个正整数N(N<= 100)代表学生的数目,接下来有N行数据每行一个整数(0~100)代表
|
||||
一个学生的成绩。
|
||||
Output
|
||||
|
||||
输出有五行格式如下:
|
||||
A nA
|
||||
B nB
|
||||
C nC
|
||||
D nD
|
||||
E nE
|
||||
其中A,B,C,D,E代表等级,nA,nB等代表个等级的人数,等级和人数之间有一个空格。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
6
|
||||
66
|
||||
73
|
||||
85
|
||||
99
|
||||
100
|
||||
59
|
||||
Output
|
||||
|
||||
A 2
|
||||
B 1
|
||||
C 1
|
||||
D 1
|
||||
E 1
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int i,na = 0,nb = 0,nc = 0,nd = 0 ,ne= 0 ,mark = 0;
|
||||
|
||||
|
||||
|
||||
for (scanf("%d",&i); i>0; i--)
|
||||
{
|
||||
scanf("%d",&mark);
|
||||
if (mark>=90)
|
||||
{
|
||||
na++;
|
||||
}
|
||||
else if(mark>=80)
|
||||
{
|
||||
nb++;
|
||||
}
|
||||
else if(mark>=70)
|
||||
{
|
||||
nc++;
|
||||
}
|
||||
|
||||
else if(mark>=60)
|
||||
{
|
||||
nd++;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
ne++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
printf("A %d\nB %d\nC %d\nD %d\nE %d\n",na,nb,nc,nd,ne);
|
||||
|
||||
return 0;
|
||||
}
|
40
Test/C/程序设计基础I/实验4--for循环结构程序设计/OJ4-1A+B for Input-Output Practice (II).c
Executable file
40
Test/C/程序设计基础I/实验4--for循环结构程序设计/OJ4-1A+B for Input-Output Practice (II).c
Executable file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
|
||||
Description
|
||||
|
||||
Your task is to Calculate a + b.
|
||||
Input
|
||||
|
||||
Your task is to Calculate a + b.
|
||||
Output
|
||||
|
||||
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.
|
||||
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
2
|
||||
1 5
|
||||
10 20
|
||||
Output
|
||||
|
||||
6
|
||||
30
|
||||
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int a, b, n, sum;
|
||||
|
||||
for (scanf("%d", &n); n > 0; n--)
|
||||
{
|
||||
scanf("%d %d", &a, &b);
|
||||
sum = a + b;
|
||||
printf("%d\n", sum);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
36
Test/C/程序设计基础I/实验4--for循环结构程序设计/OJ4-2C语言实验——计算1到n的和(循环结构).c
Executable file
36
Test/C/程序设计基础I/实验4--for循环结构程序设计/OJ4-2C语言实验——计算1到n的和(循环结构).c
Executable file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
|
||||
Description
|
||||
|
||||
从键盘上输入任意一个整数n,计算1到n的和。
|
||||
Input
|
||||
|
||||
从键盘输入任意整数n。
|
||||
Output
|
||||
|
||||
输出1到n的和。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
3
|
||||
Output
|
||||
|
||||
6
|
||||
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main ()
|
||||
{
|
||||
int n, sum;
|
||||
|
||||
scanf("%d", &n);
|
||||
|
||||
for (sum = 0; n > 0; n--)
|
||||
{
|
||||
sum = sum + n;
|
||||
}
|
||||
printf("%d\n", sum);
|
||||
|
||||
return 0;
|
||||
}
|
46
Test/C/程序设计基础I/实验4--for循环结构程序设计/OJ4-3C语言实验——求阶乘(循环结构).c
Executable file
46
Test/C/程序设计基础I/实验4--for循环结构程序设计/OJ4-3C语言实验——求阶乘(循环结构).c
Executable file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
|
||||
Description
|
||||
|
||||
从键盘输入任意一个大于等于0的整数n,然后计算n的阶乘,并把它输出。
|
||||
|
||||
提示: 0!是 1 。
|
||||
Input
|
||||
|
||||
输入任意一个大于等于0的整数n。
|
||||
Output
|
||||
|
||||
输出n!
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
3
|
||||
Output
|
||||
|
||||
6
|
||||
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main ()
|
||||
{
|
||||
int n, count;
|
||||
|
||||
scanf("%d", &n);
|
||||
|
||||
if (n != 0 && n > 0)
|
||||
{
|
||||
for (count = 1; n > 0; n--)
|
||||
{
|
||||
count = count * n;
|
||||
}
|
||||
printf("%d\n", count);
|
||||
}
|
||||
else if (0 == n)
|
||||
{
|
||||
printf("1\n");
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
42
Test/C/程序设计基础I/实验4--for循环结构程序设计/OJ4-4C语言实验——两个数比较.c
Executable file
42
Test/C/程序设计基础I/实验4--for循环结构程序设计/OJ4-4C语言实验——两个数比较.c
Executable file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
求2个数中较大者。
|
||||
Input
|
||||
|
||||
第一行为测试的数据组数N,接下来的N行分别是两个待比较的整数。
|
||||
Output
|
||||
|
||||
输出N行,每一行的值为每组数中较大的整数。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
2
|
||||
1 2
|
||||
15 10
|
||||
Output
|
||||
|
||||
2
|
||||
15
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main ()
|
||||
{
|
||||
int n, a, b;
|
||||
|
||||
for (scanf("%d", &n); 0<n; n--)
|
||||
{
|
||||
scanf("%d %d", &a, &b);
|
||||
if (a>b)
|
||||
{
|
||||
printf("%d\n", a);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%d\n", b);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
91
Test/C/程序设计基础I/实验4--for循环结构程序设计/OJ4-5做乘法.c
Executable file
91
Test/C/程序设计基础I/实验4--for循环结构程序设计/OJ4-5做乘法.c
Executable file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
|
||||
Description
|
||||
|
||||
请用C语言编写一个程序。此程序接收一个正整数N,然后打印输出“N次N*(1->N)格式”的数据。例如:此程序接收正整数5,那会输出以下格式的数据:
|
||||
5*1=5
|
||||
5*2=10
|
||||
5*3=15
|
||||
5*4=20
|
||||
5*5=25
|
||||
|
||||
Input
|
||||
|
||||
只有一个正整数N(N<=100)。
|
||||
Output
|
||||
|
||||
|
||||
输出共N行数据,如上面的例子所示。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
5
|
||||
Output
|
||||
|
||||
5*1=5
|
||||
5*2=10
|
||||
5*3=15
|
||||
5*4=20
|
||||
5*5=25
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int sum=1,i, n;
|
||||
|
||||
scanf("%d",&n);
|
||||
|
||||
for (i=1; n>=i; i++)
|
||||
{
|
||||
sum = n*i;
|
||||
printf("%d\*%d\=%d\n", n, i, sum);
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
int i;
|
||||
int y;
|
||||
scanf("%d",&n);
|
||||
for(i = 1; i <= n; i++)
|
||||
{
|
||||
y = n * i;
|
||||
printf("%d*%d=%d\n",n,i,y);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
*/
|
43
Test/C/程序设计基础I/实验4--for循环结构程序设计/OJ4-6数列求和.c
Executable file
43
Test/C/程序设计基础I/实验4--for循环结构程序设计/OJ4-6数列求和.c
Executable file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
|
||||
Description
|
||||
|
||||
数列求和是一类常见的问题,本题有一定的代表性:
|
||||
求s=a+aa+aaa+aaaa+……+aa…aa(n位)
|
||||
其中,a的值由键盘输入,位数n也由键盘输入。
|
||||
Input
|
||||
|
||||
第一行输入a的值;
|
||||
第二行输入位数n。
|
||||
Output
|
||||
|
||||
输出对n个数完成求和运算后的结果。
|
||||
比如a=3,n=6时,s=3+33+333+3333+33333+333333
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
3
|
||||
6
|
||||
Output
|
||||
|
||||
370368
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main ()
|
||||
{
|
||||
int a, n, c;
|
||||
int s = 0, i = 0;
|
||||
scanf ("%d", &a);
|
||||
scanf("%d", &n);
|
||||
|
||||
for (c=a; i<n; ++i)
|
||||
{
|
||||
s = s + c;
|
||||
c = c * 10 + a;
|
||||
}
|
||||
|
||||
printf("%d\n",s);
|
||||
|
||||
return 0;
|
||||
}
|
54
Test/C/程序设计基础I/实验4--for循环结构程序设计/P 平方数.c
Executable file
54
Test/C/程序设计基础I/实验4--for循环结构程序设计/P 平方数.c
Executable file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
飞飞特别喜欢平方数,可是他数学并不好,你能帮他计算 n 与 m 之间所有平方数之和吗?
|
||||
提示:若一个整数的开方还是整数,它就是平方数。例如:4、9、16、25是平方数。n 和 m 均可能为 0 至 100000000 内的任意整数,n、m不一定有序。
|
||||
Input
|
||||
|
||||
第一行 T 代表数据的组数。
|
||||
|
||||
接下来有 T 行,每行两个整数n,m (0 <= n, m <= 100000000)
|
||||
Output
|
||||
|
||||
输出一个整数,代表所求区间内平方数之和。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
3
|
||||
1 4
|
||||
10 3
|
||||
17 20
|
||||
Output
|
||||
|
||||
5
|
||||
13
|
||||
0
|
||||
*/
|
||||
#include<stdio.h>
|
||||
#include<math.h>
|
||||
int main()
|
||||
{
|
||||
int T,i,n,m,s,k,t;
|
||||
scanf("%d",&T);
|
||||
while(T--)
|
||||
{
|
||||
s=0;
|
||||
scanf("%d %d",&n,&m);
|
||||
if(m<n)
|
||||
{
|
||||
t=m;
|
||||
m=n;
|
||||
n=t;
|
||||
}
|
||||
for(i=n; i<=m; i++)
|
||||
{
|
||||
for(k=1; k<=sqrt(i); k++)
|
||||
{
|
||||
if(k*k==i)s=s+i;
|
||||
}
|
||||
}
|
||||
printf("%d\n",s);
|
||||
}
|
||||
return 0;
|
||||
}
|
102
Test/C/程序设计基础I/实验4--for循环结构程序设计/Q - C语言实验——打印菱形.c
Executable file
102
Test/C/程序设计基础I/实验4--for循环结构程序设计/Q - C语言实验——打印菱形.c
Executable file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
从键盘输入一个整数n(1≤n≤9),打印出指定的菱形。
|
||||
Input
|
||||
|
||||
正整数n(1≤n≤9)。
|
||||
Output
|
||||
|
||||
指定的菱形。
|
||||
第一行前面有n-1个空格,第二行有n-2个空格,依此类推。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
5
|
||||
Output
|
||||
|
||||
*
|
||||
***
|
||||
*****
|
||||
*******
|
||||
*********
|
||||
*******
|
||||
*****
|
||||
***
|
||||
*
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int n,i,t,t2,clock;
|
||||
scanf("%d",&n);
|
||||
t=n;
|
||||
t2=1;
|
||||
clock=2*n-1;
|
||||
while (clock!=n-1)
|
||||
{
|
||||
for (i=t-1;i>0; i--)
|
||||
{
|
||||
printf(" ");
|
||||
}
|
||||
for (i=t2; i>0; i--)
|
||||
{
|
||||
printf("*");
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
|
||||
t=t-1;
|
||||
t2=t2+2;
|
||||
clock--;
|
||||
}
|
||||
t=2*n-2;
|
||||
t2=1;
|
||||
while (clock!=0)
|
||||
{
|
||||
for (i=t2; i>0; i--)
|
||||
{
|
||||
printf(" ");
|
||||
}
|
||||
for (i=t;i!=0; i--)
|
||||
{
|
||||
printf("*");
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
|
||||
t=t-1;
|
||||
t2++;
|
||||
clock--;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int n,i,j;
|
||||
scanf("%d",&n);
|
||||
for(i=1;i<=n;i++)
|
||||
{
|
||||
for(j=1;j<=n-i;j++)
|
||||
printf(" ");
|
||||
for(j=1;j<=i;j++)
|
||||
printf("*");
|
||||
for(j=1;j<i;j++)
|
||||
printf("*");
|
||||
printf("\n");
|
||||
}
|
||||
for(i=n-1;i>0;i--)
|
||||
{
|
||||
for(j=1;j<=n-i;j++)
|
||||
printf(" ");
|
||||
for(j=1;j<=i;j++)
|
||||
printf("*");
|
||||
for(j=i-1;j>0;j--)
|
||||
printf("*");
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
79
Test/C/程序设计基础I/实验4--for循环结构程序设计/R 水仙花数.c
Executable file
79
Test/C/程序设计基础I/实验4--for循环结构程序设计/R 水仙花数.c
Executable file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,是这样定义的:
|
||||
“水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=13+53+33。
|
||||
现在要求输出所有在m和n范围内的水仙花数。
|
||||
Input
|
||||
|
||||
输入数据有多组,每组占一行,包括两个整数m和n(100<=m<=n<=999)。
|
||||
Output
|
||||
|
||||
对于每个测试实例,要求输出所有在给定范围内的水仙花数,就是说,输出的水仙花数必须大于等于m,并且小于等于n,如果有多个,则要求从小到大排列在一行内输出,之间用一个空格隔开;
|
||||
如果给定的范围内不存在水仙花数,则输出no;
|
||||
每个测试实例的输出占一行。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
100 120
|
||||
300 380
|
||||
Output
|
||||
|
||||
no
|
||||
370 371
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main ()
|
||||
{
|
||||
int m,n,n1,n2,t,i,sum=0,judge=0,t2,i2;
|
||||
while (scanf("%d %d",&m, &n)!=EOF)
|
||||
{
|
||||
t2=0;
|
||||
if(m>n)
|
||||
{
|
||||
t=n;
|
||||
n=m;
|
||||
m=t;
|
||||
}
|
||||
|
||||
for (i=m; i<=n; i++)//求范围内水仙花数
|
||||
{
|
||||
for (i2=3,t=i; i2>0; i2--)//循环取数求立方和
|
||||
{
|
||||
n1=t%10;
|
||||
n2=n1*n1*n1;
|
||||
|
||||
sum=sum+n2;
|
||||
|
||||
t=t/10;
|
||||
}
|
||||
|
||||
if (sum==i)
|
||||
{
|
||||
if (t2==0)
|
||||
{
|
||||
printf("%d",i);//输出第一个水仙花数
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(" %d",i);//输出非第一个数
|
||||
}
|
||||
t2++;
|
||||
judge++;
|
||||
sum=0;//sum初始化
|
||||
}
|
||||
else
|
||||
{
|
||||
sum=0;
|
||||
}
|
||||
}
|
||||
if (judge==0)
|
||||
{
|
||||
printf("no");
|
||||
}
|
||||
printf("\n");//换行
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
21
Test/C/程序设计基础I/实验4--for循环结构程序设计/S C语言实验——余弦.c
Executable file
21
Test/C/程序设计基础I/实验4--for循环结构程序设计/S C语言实验——余弦.c
Executable file
@ -0,0 +1,21 @@
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
double x, sum, t, item;
|
||||
int n, i;
|
||||
while (scanf("%lf %d", &x, &n)==2)
|
||||
{
|
||||
t = x*x;
|
||||
item = 1.0;
|
||||
sum = 1.0;
|
||||
for (i=1; i<=n; i++)
|
||||
{
|
||||
item *= -t;
|
||||
item /= (i*2-1)*(i*2);
|
||||
sum += item;
|
||||
}
|
||||
printf("%.4lf\n", sum);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
81
Test/C/程序设计基础I/实验4--for循环结构程序设计/T 完美的素数.c
Executable file
81
Test/C/程序设计基础I/实验4--for循环结构程序设计/T 完美的素数.c
Executable file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
素数又称质数。指一个大于1的自然数,除了1和此整数自身外,不能被其他自然数整除的数。我们定义:如果一个素数是完美的素数,当且仅当它的每一位数字之和也是一个素数。现在给你一个正整数,你需要写个程序判断一下这个数按照上面的定义是不是一个完美的素数。
|
||||
Input
|
||||
|
||||
输入包含多组测试数据。
|
||||
每组测试数据只包含一个正整数 n (1 < n <= 10^6)。
|
||||
Output
|
||||
|
||||
对于每组测试数据,如果 n 是完美的素数,输出“YES”,否则输出“NO”(输出均不含引号)。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
11
|
||||
13
|
||||
Output
|
||||
|
||||
YES
|
||||
NO
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
long long int n,temp = 0,sum=0,i;
|
||||
|
||||
while (scanf("%lld",&n)!=EOF)
|
||||
{
|
||||
if(n==1||n==2)
|
||||
{
|
||||
printf("YES\n");
|
||||
continue;
|
||||
}
|
||||
temp=0;
|
||||
sum=0;
|
||||
if(n>10)
|
||||
{
|
||||
temp=n;
|
||||
while (temp>0)
|
||||
{
|
||||
sum=sum+temp%10;
|
||||
temp=temp/10;
|
||||
}
|
||||
}
|
||||
else
|
||||
sum=n;
|
||||
|
||||
for (i=2; i<n; i++)
|
||||
{
|
||||
if(n%i==0)
|
||||
temp++;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
|
||||
for (i=2; i<sum; i++)
|
||||
{
|
||||
if(sum%i==0)
|
||||
temp++;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (temp==0)
|
||||
{
|
||||
printf("YES\n");
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
printf("NO\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
40
Test/C/程序设计基础I/实验4--for循环结构程序设计/U A+B for Input-Output Practice (IV).c
Executable file
40
Test/C/程序设计基础I/实验4--for循环结构程序设计/U A+B for Input-Output Practice (IV).c
Executable file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
Your task is to Calculate the sum of some integers.
|
||||
Input
|
||||
|
||||
Input contains multiple test cases. Each test case contains a integer N, and then N integers follow in the same line. A test case starting with 0 terminates the input and this test case is not to be processed.
|
||||
Output
|
||||
|
||||
For each group of input integers you should output their sum in one line, and with one line of output for each line in input.
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
4 1 2 3 3
|
||||
5 1 2 4 4 5
|
||||
0
|
||||
Output
|
||||
|
||||
9
|
||||
16
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int n,i,sum,x;
|
||||
while(scanf("%d",&n)!=EOF&&n)
|
||||
{
|
||||
sum=0;
|
||||
for(i=0; i<n; i++)
|
||||
{
|
||||
scanf("%d",&x);
|
||||
sum=sum+x;
|
||||
}
|
||||
printf("%d\n",sum);
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
48
Test/C/程序设计基础I/实验4--for循环结构程序设计/V - 小金掰呀掰不够玉米.c
Executable file
48
Test/C/程序设计基础I/实验4--for循环结构程序设计/V - 小金掰呀掰不够玉米.c
Executable file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
众所周知,C语言的学习是我们程序设计基础的重点和主要内容。
|
||||
有一天,小金(a1s4z5)觉得好饿、好饿,于是去地里找玉米吃。他拿了一个很大的背包,可以装下很多很多玉米。
|
||||
他掰玉米有一个习惯,第1次的时候掰1个,第2次的时候掰2个,第3次的时候掰3个...第n次的时候掰n个,他打算掰完第n次的时候就回家吃玉米。
|
||||
在苞米地里,他越掰越高兴越掰越高兴,终于当他摩擦到要停不下来的时候,发现自己根本背不动他的背包了。于是他要将前m次掰的玉米全都扔掉才能回家开饭。但是小金的数学很不(li)好(hai),请你帮他算一算袋子里还有多少玉米。
|
||||
Input
|
||||
|
||||
多组输入。
|
||||
每组输入两个空格隔开的整数n和m,含义如题意描述。(0 < m < n < 10^4)
|
||||
Output
|
||||
|
||||
输出小金的背包里最后剩下多少玉米。输入输出各占一行,保证数据合法。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
5 2
|
||||
6 3
|
||||
Output
|
||||
|
||||
12
|
||||
15
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int a,sum=0,i,n,m,sum2=0;
|
||||
while (scanf("%d %d",&n,&m)!=EOF)
|
||||
{
|
||||
sum=0;
|
||||
sum2=0;
|
||||
for (i = 0; i <= n; i++)
|
||||
{
|
||||
sum = sum + i;
|
||||
}
|
||||
|
||||
for (i = 0; i <= m; i++)
|
||||
{
|
||||
sum2 = sum2 + i;
|
||||
}
|
||||
|
||||
printf("%d\n", sum - sum2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
37
Test/C/程序设计基础I/实验4--for循环结构程序设计/W - C:C++练习7---求某个范围内的所有素数.c
Executable file
37
Test/C/程序设计基础I/实验4--for循环结构程序设计/W - C:C++练习7---求某个范围内的所有素数.c
Executable file
@ -0,0 +1,37 @@
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int n,flag,i,i2,count = 0;
|
||||
|
||||
scanf("%d",&n);
|
||||
|
||||
for (i=2; i<n; i++)
|
||||
{
|
||||
flag=0;
|
||||
if (n==2)
|
||||
{
|
||||
printf("2 ");
|
||||
}
|
||||
for (i2=2; i2<i; i2++)
|
||||
{
|
||||
if (i%i2==0)
|
||||
{
|
||||
flag++;
|
||||
break;
|
||||
}
|
||||
else
|
||||
continue;
|
||||
}
|
||||
if (flag==0)
|
||||
{
|
||||
printf("%d ",i);
|
||||
count++;
|
||||
}
|
||||
if (count%10==0)
|
||||
{
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
61
Test/C/程序设计基础I/实验4--for循环结构程序设计/X - 九九乘法表.c
Executable file
61
Test/C/程序设计基础I/实验4--for循环结构程序设计/X - 九九乘法表.c
Executable file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
九九乘法表是数学学习的基础,今天我们就来看看乘法表的相关问题。《九九乘法歌诀》,又常称为“小九九”,如下图所示。你的任务是写一个程序,对于给定的一个正整数 n ,输出“九九乘法表”的前 n 行。例如,输入 n 为 9,你的程序的输出将为下图:
|
||||
|
||||
|
||||
Input
|
||||
|
||||
输入包含多组测试数据,以 EOF 结束。每组测试数据只包含一个正整数 n (0 < n < 10)。
|
||||
Output
|
||||
|
||||
对于每组测试数据,输出上图所示“九九乘法表”的前 n 行。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
2
|
||||
3
|
||||
Output
|
||||
|
||||
1*1=1
|
||||
1*2=2 2*2=4
|
||||
1*1=1
|
||||
1*2=2 2*2=4
|
||||
1*3=3 2*3=6 3*3=9
|
||||
Hint
|
||||
|
||||
必须使用for循环,如果你的代码中出现例如
|
||||
|
||||
if(n == 1) printf(“1*1=1\\n”);
|
||||
|
||||
if(n == 2) printf(“1*1=1\\n1*2=2 2*2=4\\n”);
|
||||
|
||||
或其类似语句,本题不得分。
|
||||
SubmitSolutions
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int n,i,i2,mu,flag=0;
|
||||
|
||||
while (scanf("%d",&n)!=EOF)
|
||||
for (i=1;i<=n;i++)
|
||||
{
|
||||
flag=0;
|
||||
for (i2=1;i2<=i;i2++)
|
||||
{
|
||||
mu=i*i2;
|
||||
if (flag==0)
|
||||
printf("%d*%d=%d",i2,i,mu);
|
||||
else
|
||||
printf(" %d*%d=%d",i2,i,mu);
|
||||
flag++;
|
||||
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
68
Test/C/程序设计基础I/实验4--for循环结构程序设计/Y 区域内点的个数.c
Executable file
68
Test/C/程序设计基础I/实验4--for循环结构程序设计/Y 区域内点的个数.c
Executable file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
X晚上睡不着的时候不喜欢玩手机,也不喜欢打游戏,他喜欢数星星。
|
||||
Input
|
||||
|
||||
多组输入。
|
||||
|
||||
每组先输入一个整数N(N <= 10000),接着输入两个点代表矩形的左下点B(x,y)和右上点T(x,y),然后输入N个(X,Y)代表N颗星星。问有多少颗星星在窗子内部,在窗边上的不计。
|
||||
Output
|
||||
|
||||
输出一个整数,代表有多少颗星星在窗子内部。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
3
|
||||
0 1
|
||||
3 4
|
||||
1 1
|
||||
2 2
|
||||
3 3
|
||||
2
|
||||
1 1
|
||||
5 5
|
||||
4 4
|
||||
0 6
|
||||
Output
|
||||
|
||||
1
|
||||
1
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int n,sum,i,x2,y2,x0,y0,x1,y1,temp;
|
||||
|
||||
while (scanf("%d",&n)!=EOF)
|
||||
{
|
||||
scanf("%d %d",&x0,&y0);
|
||||
scanf("%d %d",&x1,&y1);
|
||||
|
||||
if(x0>x1)
|
||||
{
|
||||
temp=x0;
|
||||
x0=x1;
|
||||
x1=temp;
|
||||
}
|
||||
if(y0>y1)
|
||||
{
|
||||
temp=y1;
|
||||
y0=y1;
|
||||
y1=temp;
|
||||
}
|
||||
|
||||
sum=0;
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
scanf("%d %d",&x2,&y2);
|
||||
if ((x2<x1&&x2>x0)&&(y2<y1&&y2>y0))
|
||||
{
|
||||
sum++;
|
||||
}
|
||||
}
|
||||
printf("%d\n",sum);
|
||||
}
|
||||
return 0;
|
||||
}
|
70
Test/C/程序设计基础I/实验5-一维数组/A - C语言实验——最值.c
Executable file
70
Test/C/程序设计基础I/实验5-一维数组/A - C语言实验——最值.c
Executable file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
有一个长度为n的整数序列,其中最大值和最小值不会出现在序列的第一和最后一个位置。
|
||||
请写一个程序,把序列中的最小值与第一个数交换,最大值与最后一个数交换。输出转换好的序列。
|
||||
Input
|
||||
|
||||
输入包括两行。
|
||||
第一行为正整数n(1≤n≤10)。
|
||||
第二行为n个正整数组成的序列。
|
||||
Output
|
||||
|
||||
输出转换好的序列。数据之间用空格隔开。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
6
|
||||
2 3 8 1 4 5
|
||||
Output
|
||||
|
||||
1 3 5 2 4 8
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int n,i,t=0,t2=65535,temp,ima=0,imi=0;
|
||||
|
||||
scanf("%d",&n);
|
||||
|
||||
int a[n];
|
||||
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
scanf("%d", &a[i]);
|
||||
}//输入
|
||||
|
||||
for(i=0;i<n;i++)//选出最大最小值
|
||||
{
|
||||
if(a[i]>=t)//最大
|
||||
{
|
||||
t=a[i];
|
||||
ima=i;
|
||||
}
|
||||
|
||||
if(a[i]<=t2)//最小
|
||||
{
|
||||
t2=a[i];
|
||||
imi=i;
|
||||
}
|
||||
}
|
||||
|
||||
temp=a[0];
|
||||
a[0]=a[imi];
|
||||
a[imi]=temp;
|
||||
|
||||
temp=a[n-1];
|
||||
a[n-1]=a[ima];
|
||||
a[ima]=temp;
|
||||
|
||||
for (i=0;i<n;i++)//输出
|
||||
{
|
||||
if(i==0)
|
||||
printf("%d",a[0]);
|
||||
else
|
||||
printf(" %d", a[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
72
Test/C/程序设计基础I/实验5-一维数组/B - C语言实验——整数位.c
Executable file
72
Test/C/程序设计基础I/实验5-一维数组/B - C语言实验——整数位.c
Executable file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
Description
|
||||
输入一个不多于5位的正整数,要求:
|
||||
(1)求出它是几位数;
|
||||
(2)分别输出每一位数字;
|
||||
(3)按逆序输出各位数字。
|
||||
|
||||
Input
|
||||
输入一个不多于5位的正整数。
|
||||
|
||||
Output
|
||||
输出数据有3行,第一行为正整数位数,第二行为各位数字,第三行为逆序的各位数字。
|
||||
|
||||
Sample
|
||||
Input
|
||||
123
|
||||
Output
|
||||
3
|
||||
1 2 3
|
||||
3 2 1
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
long int a,n;
|
||||
int i=0,count=0;
|
||||
|
||||
scanf("%ld",&a);
|
||||
|
||||
n=a;
|
||||
|
||||
while (n>0)
|
||||
{
|
||||
n=n/10;
|
||||
count++;
|
||||
}
|
||||
|
||||
int num[count];
|
||||
|
||||
n=a;
|
||||
|
||||
while (n>0)
|
||||
{
|
||||
num[i]=n%10;
|
||||
i++;
|
||||
n=n/10;
|
||||
}
|
||||
|
||||
printf("%d\n",count);
|
||||
|
||||
for(i=count-1;i>=0;i--)
|
||||
{
|
||||
if (i==count-1)
|
||||
printf("%d",num[count-1]);
|
||||
else
|
||||
printf(" %d",num[i]);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
for(i=0;i<count;i++)
|
||||
{
|
||||
if (i==0)
|
||||
printf("%d",num[0]);
|
||||
else
|
||||
printf(" %d",num[i]);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
62
Test/C/程序设计基础I/实验5-一维数组/C - 小鑫数数儿.c
Executable file
62
Test/C/程序设计基础I/实验5-一维数组/C - 小鑫数数儿.c
Executable file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
某天小鑫忽然得到了许多的数字,他很好学,老师给他布置了一个任务,求出这些数字中,小于他们平均数、等于他们平均数、大于他们平均数的数字的数量是多少。(对于出现的平均数,保证都是整数,不会出现浮点数)
|
||||
Input
|
||||
|
||||
多组输入。
|
||||
对于每次的输入,第一行一个整数N(1 <= N <= 10),代表数字的个数。
|
||||
|
||||
接下来的一行,输入N个整数M(0 <= M <= 100)。
|
||||
Output
|
||||
|
||||
输出包含三个数,第一个跟第二个数后面是空格,最后一个数后面是换行。
|
||||
第一个数是这些数字中小于他们平均数的数字的个数,第二个数为等于他们平均数的数字的个数,第三个数为大于他们平均数的数字的个数。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
3
|
||||
1 2 3
|
||||
5
|
||||
2 4 4 5 5
|
||||
Output
|
||||
|
||||
1 1 1
|
||||
1 2 2
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int nmax,nmin,ave,n,i,sum,count;
|
||||
|
||||
while (scanf("%d",&n)!=EOF)
|
||||
{
|
||||
nmax = 0;
|
||||
nmin = 0;
|
||||
sum=0;
|
||||
count=0;
|
||||
|
||||
int a[n];
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
scanf("%d", &a[i]);
|
||||
sum = sum + a[i];
|
||||
}
|
||||
|
||||
ave = sum / n;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
if (a[i] > ave)
|
||||
nmax++;
|
||||
if (a[i]==ave)
|
||||
count++;
|
||||
if (a[i]<ave)
|
||||
nmin++;
|
||||
}
|
||||
printf("%d %d %d\n",nmin,count,nmax);
|
||||
}
|
||||
return 0;
|
||||
}
|
61
Test/C/程序设计基础I/实验5-一维数组/D 区间之和.c
Executable file
61
Test/C/程序设计基础I/实验5-一维数组/D 区间之和.c
Executable file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
|
||||
|
||||
给定一个由 n 个整数组成的序列A1,A2,……, An 和两个整数L,R,你的任务是写一个程序来计算序列号在[L,R](这是一个闭区间) 这段位置区间内所有数的总和。
|
||||
|
||||
|
||||
Input
|
||||
|
||||
|
||||
|
||||
输入只有一组测试数据:
|
||||
|
||||
测试数据的第一行为一个整数 n (1< n < 10000);
|
||||
|
||||
第二行为 n 个 int 类型的整数;
|
||||
|
||||
第三行为两个整数 L,R(0 < L < R <= n)。
|
||||
Output
|
||||
|
||||
|
||||
|
||||
输出序列号在区间[L,R]内所有数的和,数据保证和在 int 类型范围内。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
5
|
||||
3 5 6 2 9
|
||||
2 4
|
||||
Output
|
||||
|
||||
13
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int n=0, sum=0, l, r, i;
|
||||
|
||||
scanf("%d", &n);
|
||||
|
||||
int a[n];
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
scanf("%d", &a[i]);
|
||||
}
|
||||
|
||||
scanf("%d %d", &l, &r);
|
||||
|
||||
for (i = l-1; i < r; i++)
|
||||
{
|
||||
sum = sum + a[i];
|
||||
|
||||
}
|
||||
|
||||
printf("%d\n",sum);
|
||||
|
||||
return 0;
|
||||
}
|
59
Test/C/程序设计基础I/实验5-一维数组/E C语言实验——分割整数.c
Executable file
59
Test/C/程序设计基础I/实验5-一维数组/E C语言实验——分割整数.c
Executable file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
从键盘输入一个长整数(不超过10位),从高位开始逐位分割并输出。
|
||||
Input
|
||||
|
||||
正整数n,不含前导零。
|
||||
Output
|
||||
|
||||
分割的整数序列,各整数之间用空格格开。
|
||||
注意,最后一个数字后面没有空格!
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
678123
|
||||
Output
|
||||
|
||||
6 7 8 1 2 3
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
long long int num,sum=0,n,i=0;
|
||||
|
||||
scanf("%lld",&num);
|
||||
|
||||
n=num;
|
||||
|
||||
while (n>0)
|
||||
{
|
||||
n=n/10;
|
||||
sum++;
|
||||
}
|
||||
|
||||
int a[sum];
|
||||
|
||||
for(i=0;i<sum;i++)
|
||||
{
|
||||
a[i]=num%10;
|
||||
num=num/10;
|
||||
}
|
||||
|
||||
for(i=sum-1;i>=0;i--)
|
||||
{
|
||||
if (i==sum-1)
|
||||
{
|
||||
printf("%d",a[sum-1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(" %d",a[i]);
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
112
Test/C/程序设计基础I/实验5-一维数组/F 众数.c
Executable file
112
Test/C/程序设计基础I/实验5-一维数组/F 众数.c
Executable file
@ -0,0 +1,112 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
|
||||
|
||||
给定一个由 n 个整数组成的序列A1,A2,……, An 和两个整数L,R,你的任务是写一个程序来计算序列号在[L,R](这是一个闭区间) 这段位置区间内所有数的总和。
|
||||
|
||||
|
||||
Input
|
||||
|
||||
|
||||
|
||||
输入只有一组测试数据:
|
||||
|
||||
测试数据的第一行为一个整数 n (1< n < 10000);
|
||||
|
||||
第二行为 n 个 int 类型的整数;
|
||||
|
||||
第三行为两个整数 L,R(0 < L < R <= n)。
|
||||
Output
|
||||
|
||||
|
||||
|
||||
输出序列号在区间[L,R]内所有数的和,数据保证和在 int 类型范围内。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
5
|
||||
3 5 6 2 9
|
||||
2 4
|
||||
Output
|
||||
|
||||
13
|
||||
*/
|
||||
/*TLE
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int n,i,i2,count=0,judge=50;
|
||||
while ((scanf("%d",&n)!=EOF)||(judge!=0))
|
||||
{
|
||||
|
||||
int a[n], c[n];
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
scanf("%d", &a[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
for (i2 = 0; i2 < n; i2++)
|
||||
{
|
||||
if (a[i] == a[i2])
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
c[i] = count;
|
||||
count = 0;
|
||||
}
|
||||
|
||||
i2 = 0;
|
||||
|
||||
for (i = 1; i < n; i++)
|
||||
{
|
||||
if (c[i - 1] > c[i])
|
||||
{
|
||||
i2 = i-1;
|
||||
}
|
||||
else
|
||||
{
|
||||
i2 = i;
|
||||
}
|
||||
}
|
||||
printf("%d\n", a[i2]);
|
||||
judge--;
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int a,n;
|
||||
int i,k;
|
||||
while(~scanf("%d",&n))
|
||||
{
|
||||
int b[1001]={0},max=0;
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
scanf("%d",&a);
|
||||
b[a]++;
|
||||
/*统计“0”到“1000”对应的数出现的次数例如:若输入54,便在“b[54]”中加“1”,
|
||||
最后如果b[54]=3,即为54输入了三次*/
|
||||
}
|
||||
for(i=0;i<=1000;i++) //寻找最大次数;
|
||||
{
|
||||
if(b[i]>max)
|
||||
{
|
||||
max = b[i];
|
||||
k = i; //标记其下标;
|
||||
}
|
||||
}
|
||||
printf("%d\n",k);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
52
Test/C/程序设计基础I/实验5-一维数组/G 小鑫爱运动.c
Executable file
52
Test/C/程序设计基础I/实验5-一维数组/G 小鑫爱运动.c
Executable file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
Description
|
||||
小鑫非常喜欢运动,有一次小鑫去参加110米栏的比赛,一共有10名比赛选手,小鑫是1号,由于跑的太专注,最后冲线的时候不知道自己是第几名,只知道每个人最后的成绩,聪明的你可不可以帮帮他?
|
||||
|
||||
Input
|
||||
多组输入。
|
||||
|
||||
先输入一个10,
|
||||
然后每组输入10个整数,代表10个选手的110米栏成绩m,代表1号到N号的N个选手的成绩m,m范围是(0 < m < 100)。
|
||||
|
||||
Output
|
||||
输出只有一行,代表小鑫最后的名次是多少。
|
||||
|
||||
因为小鑫长得丑,成绩相同时,他总是排在前面。
|
||||
|
||||
|
||||
|
||||
Sample
|
||||
Input
|
||||
10
|
||||
2 5 3 9 7 10 23 12 43 5
|
||||
10
|
||||
6 1 7 9 3 4 8 3 2 9
|
||||
Output
|
||||
1
|
||||
6
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int n, a[10], i, i2, num = 1;
|
||||
while (scanf("%d", &n) != EOF)
|
||||
{
|
||||
for (i = 0; i < 10; i++)
|
||||
{
|
||||
scanf("%d", &a[i]);
|
||||
}
|
||||
for (i = 1; i < 10; i++)
|
||||
{
|
||||
if (a[0] > a[i])
|
||||
{
|
||||
num++;
|
||||
}
|
||||
}
|
||||
printf("%d\n", num);
|
||||
num = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
58
Test/C/程序设计基础I/实验5-一维数组/H - C语言实验——数日子.c
Executable file
58
Test/C/程序设计基础I/实验5-一维数组/H - C语言实验——数日子.c
Executable file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
光阴似箭,日月如梭,大学的时间真是宝贵,要抓紧时间AC^_^。你知道今天是这一年第几天吗,掐指一算还是要算好久,呵呵还是让计算机来做吧。这里的问题就是让你来写一个程序,输入某年某月某日,判断这一天是这一年的第几天?
|
||||
Input
|
||||
|
||||
输入第一行是数据的组数n<100,下面n行是n组数据,每组数据由3个正整数组成,分别为年、月、日,我们保证每组数据都是有效的日期。
|
||||
Output
|
||||
|
||||
输出所输入的日期是这一年的第几天。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
2
|
||||
2009 1 1
|
||||
2008 1 3
|
||||
Output
|
||||
|
||||
1
|
||||
3
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int i,n;
|
||||
|
||||
int y,m,d,sum,i2;
|
||||
|
||||
|
||||
while(scanf("%d",&n)!=EOF)
|
||||
{
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
int c[12]={31,28,31,30,31,30,31,31,30,31,30,31};
|
||||
|
||||
sum=0;
|
||||
scanf("%d %d %d",&y,&m,&d);
|
||||
if ((y% 4 == 0 && y % 100 != 0) || y% 400 == 0)
|
||||
{
|
||||
c[1]=29;
|
||||
}
|
||||
|
||||
if (m!=1)
|
||||
{
|
||||
for (i2=1; i2<m; i2++)
|
||||
{
|
||||
sum=sum+c[i2-1];
|
||||
}
|
||||
}
|
||||
sum=sum+d;
|
||||
printf("%d\n",sum);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
55
Test/C/程序设计基础I/实验5-一维数组/H C语言实验——数日子.c
Executable file
55
Test/C/程序设计基础I/实验5-一维数组/H C语言实验——数日子.c
Executable file
@ -0,0 +1,55 @@
|
||||
#include<stdio.h>
|
||||
#include<string.h>
|
||||
int main()
|
||||
{
|
||||
long int j,n,len ;
|
||||
char str[100],t,le[5];
|
||||
|
||||
scanf("%ld",&n);
|
||||
|
||||
while(n>0)
|
||||
{
|
||||
memset(str,0,sizeof(str));
|
||||
memset(le,0,sizeof(le));
|
||||
|
||||
gets(str);
|
||||
|
||||
len = strlen(str);
|
||||
|
||||
for(j=0;j<len;j++)
|
||||
{
|
||||
if(t>='A'&&t<='Z')
|
||||
str[j]=str[j]+32;
|
||||
t=str[j];
|
||||
switch (t)
|
||||
{
|
||||
case 'a':
|
||||
le[0]++;
|
||||
break;
|
||||
case 'e':
|
||||
le[1]++;
|
||||
break;
|
||||
case 'i':
|
||||
le[2]++;
|
||||
break;
|
||||
case 'o':
|
||||
le[3]++;
|
||||
break;
|
||||
case 'u':
|
||||
le[4]++;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
printf("a:%d\n",le[0]);
|
||||
printf("e:%d\n",le[1]);
|
||||
printf("i:%d\n",le[2]);
|
||||
printf("o:%d\n",le[3]);
|
||||
printf("u:%d\n",le[4]);
|
||||
|
||||
n--;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
28
Test/C/程序设计基础I/实验5-一维数组/I - 喵帕斯之平地摔.c
Executable file
28
Test/C/程序设计基础I/实验5-一维数组/I - 喵帕斯之平地摔.c
Executable file
@ -0,0 +1,28 @@
|
||||
#include<stdio.h>
|
||||
int main ()
|
||||
{
|
||||
int n,i,a,sum=0,i2;
|
||||
|
||||
while(scanf("%d",&n)!=EOF)
|
||||
{
|
||||
int a[n];
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
scanf("%d",&a[i]);
|
||||
}
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
if(((i>1)||((i+1)<n)))
|
||||
{
|
||||
if((a[i]>a[i+1])&&(a[i]>a[i-1]))
|
||||
{
|
||||
sum++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
printf("%d\n",sum);
|
||||
sum=0;
|
||||
}
|
||||
return 0;
|
||||
}
|
110
Test/C/程序设计基础I/实验5-一维数组/J - 排序.c
Executable file
110
Test/C/程序设计基础I/实验5-一维数组/J - 排序.c
Executable file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
给你N(N<=100)个数,请你按照从小到大的顺序输出。
|
||||
Input
|
||||
|
||||
输入数据第一行是一个正整数N,第二行有N个整数。
|
||||
Output
|
||||
|
||||
输出一行,从小到大输出这N个数,中间用空格隔开。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
5
|
||||
1 4 3 2 5
|
||||
Output
|
||||
|
||||
1 2 3 4 5
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int n,i,t;
|
||||
|
||||
scanf("%d",&n);
|
||||
|
||||
int a[n];
|
||||
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
scanf("%d",&a[i]);
|
||||
}
|
||||
|
||||
for (i=0; i<n-1; i++)
|
||||
{
|
||||
if(a[i] > a[i+1])
|
||||
{
|
||||
t = a[i];
|
||||
a[i] = a[i+1];
|
||||
a[i+1] = t;
|
||||
i=0;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if(a[0] > a[1])
|
||||
{
|
||||
t = a[0];
|
||||
a[0] = a[1];
|
||||
a[1] = t;
|
||||
}
|
||||
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
if (i==0)
|
||||
{
|
||||
printf("%d",a[0]);
|
||||
}
|
||||
else
|
||||
printf(" %d",a[i]);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int n,i,t,j;
|
||||
|
||||
scanf("%d",&n);
|
||||
|
||||
int a[n];
|
||||
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
scanf("%d",&a[i]);
|
||||
}
|
||||
|
||||
for (i=0; i<n-1; i++)
|
||||
{
|
||||
for(j = 0; j < n - 1 - i; j++)
|
||||
{
|
||||
if(a[j] > a[j+1])
|
||||
{
|
||||
t = a[j];
|
||||
a[j] = a[j+1];
|
||||
a[j+1] = t;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
if (i==0)
|
||||
{
|
||||
printf("%d",a[0]);
|
||||
}
|
||||
else
|
||||
printf(" %d",a[i]);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
62
Test/C/程序设计基础I/实验5-一维数组/J-排序.c
Executable file
62
Test/C/程序设计基础I/实验5-一维数组/J-排序.c
Executable file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
Description
|
||||
|
||||
给你N(N<=100)个数,请你按照从小到大的顺序输出。
|
||||
Input
|
||||
|
||||
输入数据第一行是一个正整数N,第二行有N个整数。
|
||||
Output
|
||||
|
||||
输出一行,从小到大输出这N个数,中间用空格隔开。
|
||||
Sample
|
||||
|
||||
Input
|
||||
|
||||
5
|
||||
1 4 3 2 5
|
||||
Output
|
||||
|
||||
1 2 3 4 5
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int n,i,t,j;
|
||||
|
||||
scanf("%d",&n);
|
||||
|
||||
int a[n];
|
||||
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
scanf("%d",&a[i]);
|
||||
}
|
||||
|
||||
for (i=0; i<n-1; i++)
|
||||
{
|
||||
for(j = 0; j < n - 1 - i; j++)
|
||||
{
|
||||
if(a[j] > a[j+1])
|
||||
{
|
||||
t = a[j];
|
||||
a[j] = a[j+1];
|
||||
a[j+1] = t;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
if (i==0)
|
||||
{
|
||||
printf("%d",a[0]);
|
||||
}
|
||||
else
|
||||
printf(" %d",a[i]);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user