iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 5
0
自我挑戰組

有志者,事竟成。系列 第 5

Day5 第二十一題~第二十五題

  • 分享至 

  • twitterImage
  •  

第二十一題UVa11185

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
	
	long N;
	while(cin>>N)
	{
		string threebase="";
		if(N==0)
			threebase="0";
		if(N<0)
			break;
		
		while(N>0)
		{
			threebase+=(N%3)+48;
			N/=3;
		}
		reverse(threebase.begin(),threebase.end());
		cout<<threebase<<endl;
	} 
}

第二十二題UVa11192

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
	int num;
	while(cin>>num)
	{
		if(num==0)
			break;
		string word;
		cin>>word;
		num=word.length()/num;
		for(int i=0;i<word.length();i+=num)
			reverse(word.begin()+i,word.begin()+(i+num));
		
		cout<<word<<endl;
	}
}

第二十三題UVa11204

#include<iostream>
using namespace std;

int main()
{
	int tc;
	cin>>tc;
	while(tc--)
	{
		int N,M,number,chance=1;
		cin>>N>>M;
		int want[N]={0};
		for(int i=0;i<M;i++)
			for(int j=0;j<N;j++)
			{
				cin>>number;
				if(number==1)
					want[j]++;
			}
		for(int j=0;j<N;j++)
		{
			if(want[j]>1)
				chance*=want[j];
		}
		cout<<chance<<endl;
	}
}

第二十四題UVa11219

#include<iostream>
#include<stdio.h>
using namespace std;

int main()
{
	int tc;
	cin>>tc;
	for(int test=1;test<=tc;test++)
	{
		int d1,m1,y1,d2,m2,y2;//1==now 2==birth
		scanf("%2d/%2d/%4d",&d1,&m1,&y1);
		scanf("%2d/%2d/%4d",&d2,&m2,&y2);
		if(y2>y1||(y1==y2&&m2>m1)||(y1==y2&&m1==m2&&d2>d1))
			cout<<"Case #"<<test<<": Invalid birth date"<<endl;
		else if(y1-y2>131||(y1-y2==131&&m1>m2)||(y1-y2==131&&m1==m2&&d1>=d2))
			cout<<"Case #"<<test<<": Check birth date"<<endl;
		else 
		{
			if(m1>m2||(m1==m2&&d1>=d2))
				cout<<"Case #"<<test<<": "<<y1-y2<<endl;
			else
				cout<<"Case #"<<test<<": "<<y1-y2-1<<endl;
		}
	}
}

第二十五題UVa11332

#include<iostream>
using namespace std;

int f(int n)
{
	int ans=0;
	while(n>0)
	{
		ans+=n%10;
		n/=10;
	}
	if(ans>=10)
	return f(ans);
	else
	return ans;
}

int main()
{
	unsigned long long n;
	while(cin>>n)
	{
		if(n==0)
		break;
		cout<<f(n)<<endl;
	}
}

上一篇
Day4 第十六題~第二十題
下一篇
Day6 第二十六題~第三十題
系列文
有志者,事竟成。19
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言