一些做的过的零散的题目(poj)(二):

1003:

比较简单:之前是在ubuntu下写的程序,但是后来编码被我搞乱了。一直ac不了。就换成vs2010了

#include <stdio.h>
int main()
{
	double c;
	while((scanf("%lf",&c)!=EOF) && c!=0)
	{
		double sum = 0.0;
		int i=1;
		while(1)
		{
			sum += 1.0/(i+1);
			if(sum >= c)
				break;
			i++;
		}
		printf("%d card(s)\n",i);
	}
	return 0;
}

1006:

生物钟:运用中国剩余定理。计算过程:提供的三个周期分别为:23,28,33。

假设a,b,c使:(33*28*a) % 23 = 1(23*33*b) % 28 =1(28*23*c)%33 = 1

容易求出:a=6 b=19 c=2 

33*28*6 = 5544 23*33*19 = 14421  28*23*2 = 1288

所以ans = (5544*p + 14421*e + 1288*i - d) % (23*28*33)

#include <stdio.h>

int main()
{
	int p,e,i,d;
	int time=1;
	while(scanf("%d%d%d%d",&p,&e,&i,&d))
	{
		if(p==-1 && e==-1 && i==-1 && d==-1)
			break;
		int lcm=21252;
		int n=(5544*p+14421*e+1288*i-d+21252)%21252;
		if(n==0)
			n=21252;
		printf("Case %d: the next triple peak occurs in %d days.\n",time++,n);
	}
	return 0;
}

1007:

DNA排序:首先获取输入并求出每个序列的秩,并用short数组存放。然后按照冒泡法(稳定)排序:按照秩降序排序并输出。

#include <iostream>
#include <string.h>

using namespace std;

int get_NUM(char* str)
{
	int num = 0;
	for(int j=1;j<strlen(str);j++)
	for(int k=0;k<j;k++)
	{
		if(str[k]>str[j])
			num++;
	}
	return num;
}

int main()
{
// 	ifstream ifs;
// 	ifs.open("test.txt");
	int n,m;
	cin>>n>>m;
	char str[102][52];
	unsigned short snum[101];
	for(int i=0;i<m;i++)
	{
		cin>>str[i];
		str[i][101]=get_NUM(str[i]);
		snum[i]=get_NUM(str[i]);
	}
	unsigned short stemp;
	char temp[101];
	for(int i=0;i<m;i++)
		for(int j=m-1;j>i;j--)
		{
			if(snum[j] < snum[j-1])
			{
				strcpy(temp,str[j-1]);
				strcpy(str[j-1],str[j]);
				strcpy(str[j],temp);

				stemp = snum[j-1];
				snum[j-1] = snum[j]; 
				snum[j] = stemp;
			}
		}
	for(int i=0;i<m;i++)
	{
		//cout<<(int)(str)[i][n]<<endl;
		str[i][n]='\0';
		str[i][n+1] = '\0';
		cout<<str[i]<<endl;
	}

	return 0;
}

1008:

日历题:求出以0年0月1日为起点计算出输入日期距离它的天数,然后通过求余和除法的到具体日期。

#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

char Haab[20][8] ={"","pop","no","zip","zotz","tzec","xul","yoxkin","mol",
	"chen","yax","zac","ceh","mac","kankin","muan","pax","koyab","cumhu","uayet"};
char Tzolkin[21][10] = {"","imix","ik","akbal","kan","chicchan","cimi","manik","lamat"
	,"muluk","ok","chuen","eb","ben","ix","mem","cib","caban","eznab","canac","ahau"};

int main()
{
	int num;
	cin>>num;
	int m;
	for(int i=0;i<num;i++)
	{
		int day=0,year=0,month=0;
		char months[10]={};
		char days[5]={};
		cin>>days>>months>>year;
		for(int i=0;i<strlen(days)-1;i++)
			day = day*10 + days[i]-'0';

		if(i==0)
			cout<<num<<endl;
		//cout<<day<<months<<year<<endl;
		//cout<<day<<endl<<months<<endl<<year<<endl;
		for(int j=1;j<=19;j++)
			if(strcmp(months,Haab[j])==0)
			{
				month = j; break;
			}
		m = year*365 + day + (month-1) * 20;//以0年0月1日为起点,计算距离天数。
		// 0 - 364天
		//cout<<m<<endl;

		year = m / 260;//259 
		m %= 260;
		month = m%13 + 1;
		day = m%20 + 1;
		cout<<month<<" "<<Tzolkin[day]<<" "<<year<<endl;
	}
}

2080:
    也是一个日期题但是计算方法不太一样:将输入的日期N 按照是否是闰年 减掉365或者366。 然后按照月份的31 29 30天来减掉月份,然后剩下的就是日期数目。
   
#include <iostream>
#include <stdio.h>

using namespace std;

int leap(int year)
{
	if(year%4!=0 || (year%100==0&&year%400!=0))
		return 0;
	return 1;
}

int years[2]={365,366};
int months[2][12]={31,28,31,30,31,30,31,31,30,31,30,31,
  31,29,31,30,31,30,31,31,30,31,30,31};
char weeks[7][10] = {"Monday","Tuesday","Wednesday",
	"Thursday","Friday","Saturday","Sunday"};

int main()
{
	int n;
	while(cin>>n && n!=-1)
	{
		int month,year,week;
		week = n%7;
		
		for(year=2000;n>=years[leap(year)];year++)
			n -= years[leap(year)];
		for(month=0;n>=months[leap(year)][month];month++)
			n -= months[leap(year)][month];
		
	 printf("%d-%02d-%02d %s\n",year,month+1,n+1,weeks[(week+5)%7]);     

	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值