DAY 4
0

## Day4 第十六題~第二十題

### 第十六題 UVa10903

``````#include<iostream>
#include<iomanip>
#include<string>
using namespace std;

int main()
{
int n,k;
bool first=true;
while(cin>>n)
{
if(n==0)
break;
cin>>k;
if(!first)
cout<<endl;
first=false;
int p1,p2;
string m1,m2;
float win_low[n+1][2]={0};//0=w,1=l

for(int i=0;i<k*n*(n-1)/2;i++)
{
cin>>p1>>m1>>p2>>m2;
if(m1=="scissors"&&m2=="rock")
{
win_low[p1][1]+=1;
win_low[p2][0]+=1;
}
if(m1=="scissors"&&m2=="paper")
{
win_low[p1][0]+=1;
win_low[p2][1]+=1;
}
if(m1=="rock"&&m2=="scissors")
{
win_low[p1][0]+=1;
win_low[p2][1]+=1;
}
if(m1=="rock"&&m2=="paper")
{
win_low[p1][1]+=1;
win_low[p2][0]+=1;
}
if(m1=="paper"&&m2=="scissors")
{
win_low[p1][1]+=1;
win_low[p2][0]+=1;
}
if(m1=="paper"&&m2=="rock")
{
win_low[p1][0]+=1;
win_low[p2][1]+=1;
}
}
for(int i=1;i<=n;i++)
{
if(win_low[i][0]==0&&win_low[i][1]==0)
{
cout<<'-'<<endl;
continue;
}
cout<<fixed<<setprecision(3)<<(float)(win_low[i][0]/((float)win_low[i][0]+win_low[i][1]))<<endl;
}
}
}
``````

### 第十七題 UVa10924

``````#include<iostream>
#include<string>
#include<cmath>
using namespace std;

bool is_prime(int number)
{
for(int i=2;i<=sqrt(number);i++)
if(number%i==0)
return false;
return true;
}

int main()
{
string word;
while(cin>>word)
{
int num=0;
for(int i=0;i<word.length();i++)
{
if(word[i]>=97&&word[i]<=122)
num+=(word[i]-96);
if(word[i]>=65&&word[i]<=90)
num+=(word[i]-38);
}
if(is_prime(num))
cout<<"It is a prime word."<<endl;
else
cout<<"It is not a prime word."<<endl;
}
}
``````

### 第十八題 UVa10929

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

int main()
{
string N;
while(cin>>N)
{
int odd=0,even=0;
if(N=="0")
break;
for(int i=0;i<N.length();i+=2)
odd+=(N[i]-48);
for(int i=1;i<N.length();i+=2)
even+=(N[i]-48);
if((odd-even)%11==0||(even-odd)%11==0)
cout<<N<<" is a multiple of 11."<<endl;
else
cout<<N<<" is not a multiple of 11."<<endl;
}
}
``````

### 第十九題 UVa10963

``````#include<iostream>
using namespace std;

int main()
{
int tc;
bool first=true;
cin>>tc;
while(tc--)
{
if(!first)
cout<<endl;
bool yes=true;
int col;
cin>>col;
int n,s,bridge;
cin>>n>>s;
bridge=n-s;
while(--col)
{
cin>>n>>s;
if(bridge!=n-s)
{
yes=false;
}
}
if(yes)
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
first=false;
}
}
``````

### 第二十題 UVa11172

``````#include<iostream>
using namespace std;

int main()
{
int tc;
long long a,b;
cin>>tc;
while(tc--)
{
cin>>a>>b;
if(a>b)
cout<<'>'<<endl;
if(a<b)
cout<<'<'<<endl;
if(a==b)
cout<<'='<<endl;
}
}
``````