DAY 5
0

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

### 第二十一題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;
}
}
``````