EOJ 2986~2990 2013年编程实践课程师范班第2次上机考试

简单模拟题,主要是给编程实践没过的同学写的,希望能KO了它!

 

http://acm.cs.ecnu.edu.cn/problem.php?problemid=2986

2986 计算2的N次方

#include <stdio.h>
#define  LL long long 
 
LL a[64];
void init()
{
	a[0] = 1;
	for(int i=1; i<=63; i++)
	{
		a[i] = a[i-1]*2;
	}
 
}
int main()
{
	int cas;
	init();
	scanf("%d", &cas);
	for(int i=0; i<cas; i++)
	{
		int n;
		scanf("%d", &n);
		printf("case #%d:\n%lld\n", i, a[n]);
	}
	return 0;
}

 

 

 

http://acm.cs.ecnu.edu.cn/problem.php?problemid=2987

 

2987 判断ip 

注意本题输入格式的小技巧,其他如:scanf("%s%c", str, chr)可以连续读字符串,到chr=‘\n’时停止读入。

另外如果刚兴趣,可以了解一下sprintf()。

#include <stdio.h>
 
int main()
{
	int a,b,c,d;
	int cas;
	scanf("%d" ,&cas);
	for(int i=0; i<cas; i++)
	{
		scanf("%d.%d.%d.%d" ,&a, &b, &c, &d);
		printf("case #%d:\n", i);
		if(a < 0 || a > 255)
		{
			printf("No %d %d\n", 0, a);
			continue;
		}
		if(b < 0 || b > 255)
		{
			printf("No %d %d\n", 1, b);
			continue;
		}
		if(c < 0 || c > 255)
		{
			printf("No %d %d\n", 2, c);
			continue;
		}
		if(d < 0 || d > 255)
		{
			printf("No %d %d\n", 3, d);
			continue;
		}
		printf("Yes\n");
	}
	return 0;
}

 

 

http://acm.cs.ecnu.edu.cn/problem.php?problemid=2988

2988 密码产生器

#include <stdio.h>
char a[105];
int b[7];
int main()
 
{
	int cas;
	scanf("%d", &cas);
	for(int i=0; i<cas; i++)
	{
		scanf("%s" ,a);
		for(int j=0; j<6; j++)b[j] = 0;
		for(int j=0; a[j]!='\0'; j++)
		{		
			b[j%6] += a[j];
		}
		printf("case #%d:\n", i);
		for(int j=0; j<6; j++)
		{
			printf("%d", b[j]%10);
		}
		printf("\n");	
	}
	return 0;
}


 

 

 

http://acm.cs.ecnu.edu.cn/problem.php?problemid=2989

2989 字符串重排

按"NBA"输出,个数 不够时不输出。

#include <stdio.h>
char s[10005];
int a,b,c;
int main()
{
	int cas;
	scanf("%d" ,&cas);
	for(int i=0 ;i<cas; i++)
	{
		scanf("%s", s);
		a = b = c;
		for(int j=0; s[j]!='\0'; j++)
		{
			if(s[j] == 'N')a++;
			if(s[j] == 'B')b++;
			if(s[j] == 'A')c++;		 
		}
		printf("case #%d:\n", i);
		int d = 0;
		while(a || b || c)
		{
			if(d % 3 == 0)
			{
				if(a > 0)
				{
					printf("N");
					a --;
				}
			}
			else if(d % 3 == 1)
			{
				if(b > 0)
				{
					printf("B");
					b --;
				}
			}
			else if(d % 3 == 2)
			{
				if(c > 0)
				{
					printf("A");
					c --;
				}
			}
			d ++;
		}
		printf("\n");
	}
	return 0;
}


 

http://acm.cs.ecnu.edu.cn/problem.php?problemid=2990

2990 文献排序

qsort:http://blog.163.com/justly@yeah/blog/static/121037000200952982531680/

sort :http://www.cplusplus.com/reference/algorithm/sort/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std; 
char s[205][205];
int cmp(const void * a, const void *  b)
{//(char*)(a)
	char s1[205], s2[205];
	int i;
	strcpy(s1, (char*)(a));
	strcpy(s2, (char*)(b));
	for(i=0;s1[i]!='\0'; i++)
	{
		if(s1[i] >= 'A' && s1[i] <= 'Z')
		s1[i] = s1[i] - 'A' + 'a';
	}
	for(i=0;s2[i]!='\0'; i++)
	{
		if(s2[i] >= 'A' && s2[i] <= 'Z')
		s2[i] = s2[i] - 'A' + 'a';
	}
	return strcmp(s1,s2);
}
int main()
{
	int cas;
	//freopen("in", "r", stdin);
	scanf("%d" ,&cas);
	//getchar();
	for(int i=0; i<cas; i++)
	{
		int n;
		scanf("%d\n", &n);
		for(int j=0; j<n; j++)
		{
			gets(s[j]);
			for(int k=0; s[j][k]!='\0'; k++)
			{
				//if(s[j][k] >= 'A' && s[j][k] <= 'Z')
				//{
					//s[j][k] = s[j][k]-'A'+'a';
				//}
			}
			//puts(s[j]);
		}
		printf("case #%d:\n", i);
		qsort(s, n, sizeof(char[205]), cmp);
		for(int j=0; j<n ;j++)puts(s[j]);
	}	
	return 0;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值