#include<bits/stdc++.h> using namespace std; int main() { long long a , b,cnt=0; double num=0; while(1){ cin>>a; cin>>b; if(a==0&&b==0) break; for(int i=a; i<=b; i++){ num=sqrt(i); if(num==(int)num) cnt++; } cout<<cnt<<endl; cnt=0; } return 0; }
I have stored my online judge solutions of my own :)
Thursday, January 28, 2016
UVA 11461 | | Square Numbers
UVa 11984 A Change in Thermal Unit
#include<bits/stdc++.h>
using namespace std;
int main()
{
float t , c , f, total=0;
int counter=1;
cin>>t;
while(t--){
cin>>c;
cin>>f;
total=((5.0/9.0)*f)+c;
printf("Case %d: %.2f\n",counter,total);
counter++;
}
return 0;
}
using namespace std;
int main()
{
float t , c , f, total=0;
int counter=1;
cin>>t;
while(t--){
cin>>c;
cin>>f;
total=((5.0/9.0)*f)+c;
printf("Case %d: %.2f\n",counter,total);
counter++;
}
return 0;
}
UVA 10921 | | Find the Telephone
#include<bits/stdc++.h>
using namespace std;
int main()
{
char num[100];
int i;
while(scanf("%s",num)!=EOF){
for(i=0; i<strlen(num); i++) {
if(num[i]=='A'|| num[i]=='B'||num[i]=='C')
num[i]='2';
else if(num[i]=='D'||num[i]=='E'||num[i]=='F')
num[i]='3';
else if(num[i]=='G' ||num[i]=='H'||num[i]=='I')
num[i]='4';
else if(num[i]=='J'||num[i]=='K'||num[i]=='L')
num[i]='5';
else if(num[i]=='M'||num[i]=='N'||num[i]=='O')
num[i]='6';
else if(num[i]=='P'||num[i]=='Q'||num[i]=='R'||num[i]=='S')
num[i]='7';
else if(num[i]=='T'||num[i]=='U'||num[i]=='V')
num[i]='8';
else if(num[i]=='W'||num[i]=='X'||num[i]=='Y'||num[i]=='Z')
num[i]='9';
}
cout<<num<<"\n";
}
return 0;
}
using namespace std;
int main()
{
char num[100];
int i;
while(scanf("%s",num)!=EOF){
for(i=0; i<strlen(num); i++) {
if(num[i]=='A'|| num[i]=='B'||num[i]=='C')
num[i]='2';
else if(num[i]=='D'||num[i]=='E'||num[i]=='F')
num[i]='3';
else if(num[i]=='G' ||num[i]=='H'||num[i]=='I')
num[i]='4';
else if(num[i]=='J'||num[i]=='K'||num[i]=='L')
num[i]='5';
else if(num[i]=='M'||num[i]=='N'||num[i]=='O')
num[i]='6';
else if(num[i]=='P'||num[i]=='Q'||num[i]=='R'||num[i]=='S')
num[i]='7';
else if(num[i]=='T'||num[i]=='U'||num[i]=='V')
num[i]='8';
else if(num[i]=='W'||num[i]=='X'||num[i]=='Y'||num[i]=='Z')
num[i]='9';
}
cout<<num<<"\n";
}
return 0;
}
UVA 11854 - Egypt
#include<bits/stdc++.h>
long long a[1000000];
using namespace std;
int main()
{
int i;
while(1){
for(i=0; i<3; i++)
cin>>a[i];
sort(a,a+3);
if(a[0] == 0 && a[1] == 0 &&a[2] == 0)
break;
else{
if((a[0]*a[0]+a[1]*a[1])==(a[2]*a[2]))
cout<<"right\n";
else
cout<<"wrong\n";
}
}
return 0;
}
long long a[1000000];
using namespace std;
int main()
{
int i;
while(1){
for(i=0; i<3; i++)
cin>>a[i];
sort(a,a+3);
if(a[0] == 0 && a[1] == 0 &&a[2] == 0)
break;
else{
if((a[0]*a[0]+a[1]*a[1])==(a[2]*a[2]))
cout<<"right\n";
else
cout<<"wrong\n";
}
}
return 0;
}
UVA 10222 - Decode the Mad man
#include<bits/stdc++.h>
using namespace std;
int main()
{
char s[100];
int i=0;
gets(s);
for(i=0; i<strlen(s); i++) {
if(s[i]==']')
s[i]='p';
else if(s[i]=='[')
s[i]='o';
else if(s[i]=='p' || s[i]=='P')
s[i]='i';
else if(s[i]=='o' ||s[i]=='O')
s[i]='u';
else if(s[i]=='i'||s[i]=='I')
s[i]='y';
else if(s[i]=='u'||s[i]=='U')
s[i]='t';
else if(s[i]=='y'||s[i]=='Y')
s[i]='r';
else if(s[i]=='t'||s[i]=='T')
s[i]='e';
else if(s[i]=='r'||s[i]=='R')
s[i]='w';
else if(s[i]=='e'||s[i]=='E')
s[i]='q';
else if(s[i]=='\'')
s[i]='l';
else if(s[i]==';')
s[i]='k';
else if(s[i]=='l'||s[i]=='L')
s[i]='j';
else if(s[i]=='k'||s[i]=='K')
s[i]='h';
else if(s[i]=='j'||s[i]=='J')
s[i]='g';
else if(s[i]=='h'||s[i]=='H')
s[i]='f';
else if(s[i]=='g'||s[i]=='G')
s[i]='d';
else if(s[i]=='f'||s[i]=='F')
s[i]='s';
else if(s[i]=='d'||s[i]=='D')
s[i]='a';
else if(s[i]=='.')
s[i]='m';
else if(s[i]==',')
s[i]='n';
else if(s[i]=='m'||s[i]=='M')
s[i]='b';
else if(s[i]=='n'||s[i]=='N')
s[i]='v';
else if(s[i]=='b'||s[i]=='B')
s[i]='c';
else if(s[i]=='v'||s[i]=='V')
s[i]='x';
else if(s[i]=='c'||s[i]=='C')
s[i]='z';
}
puts(s);
return 0;
}
using namespace std;
int main()
{
char s[100];
int i=0;
gets(s);
for(i=0; i<strlen(s); i++) {
if(s[i]==']')
s[i]='p';
else if(s[i]=='[')
s[i]='o';
else if(s[i]=='p' || s[i]=='P')
s[i]='i';
else if(s[i]=='o' ||s[i]=='O')
s[i]='u';
else if(s[i]=='i'||s[i]=='I')
s[i]='y';
else if(s[i]=='u'||s[i]=='U')
s[i]='t';
else if(s[i]=='y'||s[i]=='Y')
s[i]='r';
else if(s[i]=='t'||s[i]=='T')
s[i]='e';
else if(s[i]=='r'||s[i]=='R')
s[i]='w';
else if(s[i]=='e'||s[i]=='E')
s[i]='q';
else if(s[i]=='\'')
s[i]='l';
else if(s[i]==';')
s[i]='k';
else if(s[i]=='l'||s[i]=='L')
s[i]='j';
else if(s[i]=='k'||s[i]=='K')
s[i]='h';
else if(s[i]=='j'||s[i]=='J')
s[i]='g';
else if(s[i]=='h'||s[i]=='H')
s[i]='f';
else if(s[i]=='g'||s[i]=='G')
s[i]='d';
else if(s[i]=='f'||s[i]=='F')
s[i]='s';
else if(s[i]=='d'||s[i]=='D')
s[i]='a';
else if(s[i]=='.')
s[i]='m';
else if(s[i]==',')
s[i]='n';
else if(s[i]=='m'||s[i]=='M')
s[i]='b';
else if(s[i]=='n'||s[i]=='N')
s[i]='v';
else if(s[i]=='b'||s[i]=='B')
s[i]='c';
else if(s[i]=='v'||s[i]=='V')
s[i]='x';
else if(s[i]=='c'||s[i]=='C')
s[i]='z';
}
puts(s);
return 0;
}
UVA 11462 - Age Sort
#include<stdio.h>
#include<algorithm>
using namespace std;
long int a[2000005],i,n;
int main()
{
while (scanf("%ld",&n)==1)
{
if (n==0)
break;
for (i=0;i<n;i++)
scanf("%ld",&a[i]);
sort(a,a+i);
for (i=0;i<n;i++)
{
printf("%ld",a[i]);
if (i<(n-1))
printf(" ");
}
printf("n");
}
return 0;
}
#include<algorithm>
using namespace std;
long int a[2000005],i,n;
int main()
{
while (scanf("%ld",&n)==1)
{
if (n==0)
break;
for (i=0;i<n;i++)
scanf("%ld",&a[i]);
sort(a,a+i);
for (i=0;i<n;i++)
{
printf("%ld",a[i]);
if (i<(n-1))
printf(" ");
}
printf("n");
}
return 0;
}
UVA 12250 | | Language Detection
#include<bits/stdc++.h> using namespace std; int main() { string s; long long cse=0; while(cin>>s){ if(s!="#"){ if(s=="HELLO") cout<<"Case "<<++cse<<": "<<"ENGLISH"<<endl; else if(s=="HOLA") cout<<"Case "<<++cse<<": "<<"SPANISH"<<endl; else if(s=="HALLO") cout<<"Case "<<++cse<<": "<<"GERMAN"<<endl; else if(s=="BONJOUR") cout<<"Case "<<++cse<<": "<<"FRENCH"<<endl; else if(s=="CIAO") cout<<"Case "<<++cse<<": "<<"ITALIAN"<<endl; else if(s=="ZDRAVSTVUJTE") cout<<"Case "<<++cse<<": "<<"RUSSIAN"<<endl; else cout<<"Case "<<++cse<<": "<<"UNKNOWN"<<endl; } else break; } }
UVA 12577 | | Hajj-e-Akbar
#include<bits/stdc++.h> using namespace std; int main() { char s[6]; long long cse=0; while(cin>>s){ if(strcmp(s,"Hajj")==0) cout<<"Case "<<++cse<<": "<<"Hajj-e-Akbar"<<endl; else if(strcmp(s,"Umrah")==0) cout<<"Case "<<++cse<<": "<<"Hajj-e-Asghar"<<endl; else break; } }
UVA 10812 | | Beat the Spread!
#include<stdio.h>
int main()
{
long int t,a,b,c,d,i;
while(scanf("%ld",&t)==1)
{
i=0;
while(i<t)
{
scanf("%ld%ld",&a,&b);
if(b>a||(a-b)%2!=0)
printf("impossible\n");
else
{
c=(a-b)/2;
d=c+b;
printf("%ld %ld\n",d,c);
}
i++;
}
}
return 0;
}
int main()
{
long int t,a,b,c,d,i;
while(scanf("%ld",&t)==1)
{
i=0;
while(i<t)
{
scanf("%ld%ld",&a,&b);
if(b>a||(a-b)%2!=0)
printf("impossible\n");
else
{
c=(a-b)/2;
d=c+b;
printf("%ld %ld\n",d,c);
}
i++;
}
}
return 0;
}
UVA 11799 | | Horror Dash
#include<stdio.h>
int main()
{
int i,t,a,b;
char c;
while(scanf("%d",&t)==1)
{
for(i=1;i<=t;i++)
{
b=0;
while(1)
{
scanf("%d",&a);
if(a>b)
b=a;
scanf("%c",&c);
if(c!=' ')
break;
}
printf("Case %d: %d\n",i,b);
}
}
}
int main()
{
int i,t,a,b;
char c;
while(scanf("%d",&t)==1)
{
for(i=1;i<=t;i++)
{
b=0;
while(1)
{
scanf("%d",&a);
if(a>b)
b=a;
scanf("%c",&c);
if(c!=' ')
break;
}
printf("Case %d: %d\n",i,b);
}
}
}
UVA 10260 | | Soundex
#include<stdio.h>
#include<string.h>
int main()
{
int i,l;
char s[100];
while(gets(s))
{
l=strlen(s);
for(i=0;i<l;i++)
{
if(s[i]=='B' || s[i]=='F' || s[i]=='P' || s[i]=='V')
{
if(s[i-1]!='B' && s[i-1]!='F' && s[i-1]!='P' && s[i-1]!='V')
printf("1");
}
else if(s[i]=='C' || s[i]=='G' || s[i]=='J' || s[i]=='K' || s[i]=='Q' || s[i]=='S' || s[i]=='X' || s[i]=='Z')
{
if(s[i-1]!='C' && s[i-1]!='G' && s[i-1]!='J' && s[i-1]!='K' && s[i-1]!='Q' && s[i-1]!='S' && s[i-1]!='X' && s[i-1]!='Z')
printf("2");
}
else if(s[i]=='D' || s[i]=='T')
{
if(s[i-1]!='D' && s[i-1]!='T')
printf("3");
}
else if(s[i]=='L')
{
if(s[i-1]!='L')
printf("4");
}
else if(s[i]=='M' || s[i]=='N')
{
if(s[i-1]!='M' && s[i-1]!='N')
printf("5");
}
else if(s[i]=='R')
{
if(s[i-1]!='R')
printf("6");
}
}
printf("\n");
}
}
#include<string.h>
int main()
{
int i,l;
char s[100];
while(gets(s))
{
l=strlen(s);
for(i=0;i<l;i++)
{
if(s[i]=='B' || s[i]=='F' || s[i]=='P' || s[i]=='V')
{
if(s[i-1]!='B' && s[i-1]!='F' && s[i-1]!='P' && s[i-1]!='V')
printf("1");
}
else if(s[i]=='C' || s[i]=='G' || s[i]=='J' || s[i]=='K' || s[i]=='Q' || s[i]=='S' || s[i]=='X' || s[i]=='Z')
{
if(s[i-1]!='C' && s[i-1]!='G' && s[i-1]!='J' && s[i-1]!='K' && s[i-1]!='Q' && s[i-1]!='S' && s[i-1]!='X' && s[i-1]!='Z')
printf("2");
}
else if(s[i]=='D' || s[i]=='T')
{
if(s[i-1]!='D' && s[i-1]!='T')
printf("3");
}
else if(s[i]=='L')
{
if(s[i-1]!='L')
printf("4");
}
else if(s[i]=='M' || s[i]=='N')
{
if(s[i-1]!='M' && s[i-1]!='N')
printf("5");
}
else if(s[i]=='R')
{
if(s[i-1]!='R')
printf("6");
}
}
printf("\n");
}
}
UVA 1585 - Score
#include <stdio.h>
#include <string.h>
int main()
{
char s[101];
int a[101],b,c,d,i,j,k,l,n,sum;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%s",s);
l=strlen(s);
for(j=0;j<l;j++)
{
if(s[j]=='O')
a[j]=1;
else if(s[j]='X')
a[j]=0;
}
c=0,sum=0;
for(k=0;k<l;k++)
{
if(a[k]==1)
{
c++;
}
if(a[k]==0)
{
c=0;
}
sum=sum+c;
}
printf("%d\n",sum);
}
return 0;
}
#include <string.h>
int main()
{
char s[101];
int a[101],b,c,d,i,j,k,l,n,sum;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%s",s);
l=strlen(s);
for(j=0;j<l;j++)
{
if(s[j]=='O')
a[j]=1;
else if(s[j]='X')
a[j]=0;
}
c=0,sum=0;
for(k=0;k<l;k++)
{
if(a[k]==1)
{
c++;
}
if(a[k]==0)
{
c=0;
}
sum=sum+c;
}
printf("%d\n",sum);
}
return 0;
}
UVA 10945 | | Mother bear
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<string>
#include<cctype>
#include<stdlib.h>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
char s[100], temp[100], t[100];
char c;
int j=0,cnt=0;
int i;
while(gets(t)){
if(strcmp(t,"DONE")==0)
break;
else{
while(1){
if(t[j]=='\0')
break;
else{
if(isalpha(t[j])>0){
s[cnt]=t[j];
cnt++;
}
}
j++;
}
s[cnt]='\0';
cnt=0;
j=0;
memset(t,'\0',strlen(t));
strcpy(temp,s);
reverse(s,s+strlen(s));
for(i=0; i<strlen(s); i++){
s[i]=toupper(s[i]);
temp[i]=toupper(temp[i]);
}
if(strcmp(s,temp)==0)
puts("You won't be eaten!");
else
puts("Uh oh..");
}
}
return 0;
}
#include<string>
#include<cstring>
#include<cstdio>
#include<string>
#include<cctype>
#include<stdlib.h>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
char s[100], temp[100], t[100];
char c;
int j=0,cnt=0;
int i;
while(gets(t)){
if(strcmp(t,"DONE")==0)
break;
else{
while(1){
if(t[j]=='\0')
break;
else{
if(isalpha(t[j])>0){
s[cnt]=t[j];
cnt++;
}
}
j++;
}
s[cnt]='\0';
cnt=0;
j=0;
memset(t,'\0',strlen(t));
strcpy(temp,s);
reverse(s,s+strlen(s));
for(i=0; i<strlen(s); i++){
s[i]=toupper(s[i]);
temp[i]=toupper(temp[i]);
}
if(strcmp(s,temp)==0)
puts("You won't be eaten!");
else
puts("Uh oh..");
}
}
return 0;
}
UVA 13012 | | Identifying tea
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t,c,i,n;
while(cin>>t)
{
n=0;
for(i=1;i<=5;i++)
{
cin>>c;
if(c==t)
{
n++;
}
}
cout<<n<<endl;
}
return 0;
}
using namespace std;
int main()
{
int t,c,i,n;
while(cin>>t)
{
n=0;
for(i=1;i<=5;i++)
{
cin>>c;
if(c==t)
{
n++;
}
}
cout<<n<<endl;
}
return 0;
}
UVA 12592 | | Slogan Learning of Princes
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<string>
#include<cctype>
#include<stdlib.h>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
char s[200][200], t[200][200];
int n, q;
cin>>n;
getchar();
for(int i=0; i<n*2; i++)
gets(s[i]);
cin>>q;
getchar();
for(int i=0; i<q; i++)
gets(t[i]);
for(int i=0; i<q; i++){
for(int j=0; j<n*2; j++){
if(strcmp(t[i],s[j])==0)
cout<<s[j+1]<<"\n";
}
}
return 0;
}
#include<string>
#include<cstring>
#include<cstdio>
#include<string>
#include<cctype>
#include<stdlib.h>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
char s[200][200], t[200][200];
int n, q;
cin>>n;
getchar();
for(int i=0; i<n*2; i++)
gets(s[i]);
cin>>q;
getchar();
for(int i=0; i<q; i++)
gets(t[i]);
for(int i=0; i<q; i++){
for(int j=0; j<n*2; j++){
if(strcmp(t[i],s[j])==0)
cout<<s[j+1]<<"\n";
}
}
return 0;
}
UVA 11878 | | Homework Checker
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<string>
#include<cctype>
#include<stdlib.h>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
char s[100],p,q;
int a,b, i ,cnt=0, k;
while(scanf("%d%c%d%c%s",&a,&p,&b,&q,s)==5){
//cin>>a>>p>>b>>q>>s;
if(s[0]!='?'){
if(p=='+'){
if(a+b==atoi(s))
cnt++;
}
else if(p=='-')
if(a-b==atoi(s))
cnt++;
}
}
cout<<cnt<<"\n";
cnt=0;
return 0;
}
#include<string>
#include<cstring>
#include<cstdio>
#include<string>
#include<cctype>
#include<stdlib.h>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
char s[100],p,q;
int a,b, i ,cnt=0, k;
while(scanf("%d%c%d%c%s",&a,&p,&b,&q,s)==5){
//cin>>a>>p>>b>>q>>s;
if(s[0]!='?'){
if(p=='+'){
if(a+b==atoi(s))
cnt++;
}
else if(p=='-')
if(a-b==atoi(s))
cnt++;
}
}
cout<<cnt<<"\n";
cnt=0;
return 0;
}
UVA 11192 | | Group Reverse
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<string>
#include<ctype.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
char s[100],temp[100];
int i, t , j, cnt=0, len;
while(cin>>t){
if(t==0)
break;
getchar();
gets(s);
len=strlen(s)/t;
for(i=0; i<strlen(s); i+=len){
for(j=i+len; ; j--){
cout<<s[j-1];
cnt++;
if(cnt==len)
break;
}
cnt=0;
}
cout<<"\n";
}
return 0;
}
#include<string>
#include<cstring>
#include<cstdio>
#include<string>
#include<ctype.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
char s[100],temp[100];
int i, t , j, cnt=0, len;
while(cin>>t){
if(t==0)
break;
getchar();
gets(s);
len=strlen(s)/t;
for(i=0; i<strlen(s); i+=len){
for(j=i+len; ; j--){
cout<<s[j-1];
cnt++;
if(cnt==len)
break;
}
cnt=0;
}
cout<<"\n";
}
return 0;
}
UVA 10082 | | WERTYU
#include<stdio.h>
int main()
{
char c;
while ( scanf("%c",&c)==1)
{
if (c=='1')
printf("`");
if (c=='2')
printf("1");
if (c=='3')
printf("2");
if (c=='4')
printf("3");
if (c=='5')
printf("4");
if (c=='6')
printf("5");
if (c=='7')
printf("6");
if (c=='8')
printf("7");
if (c=='9')
printf("8");
if (c=='0')
printf("9");
if (c=='-')
printf("0");
if (c=='=')
printf("-");
if (c=='W')
printf("Q");
if (c=='E')
printf("W");
if (c=='R')
printf("E");
if (c=='T')
printf("R");
if (c=='Y')
printf("T");
if (c=='U')
printf("Y");
if (c=='I')
printf("U");
if (c=='O')
printf("I");
if (c=='P')
printf("O");
if (c=='[')
printf("P");
if (c==']')
printf("[");
if (c=='\\')
printf("]");
if (c=='S')
printf("A");
if (c=='D')
printf("S");
if (c=='F')
printf("D");
if (c=='G')
printf("F");
if (c=='H')
printf("G");
if (c=='J')
printf("H");
if (c=='K')
printf("J");
if (c=='L')
printf("K");
if (c==';')
printf("L");
if (c=='\'')
printf(";");
if (c=='X')
printf("Z");
if (c=='C')
printf("X");
if (c=='V')
printf("C");
if (c=='B')
printf("V");
if (c=='N')
printf("B");
if (c=='M')
printf("N");
if (c==',')
printf("M");
if (c=='.')
printf(",");
if (c=='/')
printf(".");
if (c==' ')
printf(" ");
if (c=='\n')
printf("\n");
}
return 0;
}
int main()
{
char c;
while ( scanf("%c",&c)==1)
{
if (c=='1')
printf("`");
if (c=='2')
printf("1");
if (c=='3')
printf("2");
if (c=='4')
printf("3");
if (c=='5')
printf("4");
if (c=='6')
printf("5");
if (c=='7')
printf("6");
if (c=='8')
printf("7");
if (c=='9')
printf("8");
if (c=='0')
printf("9");
if (c=='-')
printf("0");
if (c=='=')
printf("-");
if (c=='W')
printf("Q");
if (c=='E')
printf("W");
if (c=='R')
printf("E");
if (c=='T')
printf("R");
if (c=='Y')
printf("T");
if (c=='U')
printf("Y");
if (c=='I')
printf("U");
if (c=='O')
printf("I");
if (c=='P')
printf("O");
if (c=='[')
printf("P");
if (c==']')
printf("[");
if (c=='\\')
printf("]");
if (c=='S')
printf("A");
if (c=='D')
printf("S");
if (c=='F')
printf("D");
if (c=='G')
printf("F");
if (c=='H')
printf("G");
if (c=='J')
printf("H");
if (c=='K')
printf("J");
if (c=='L')
printf("K");
if (c==';')
printf("L");
if (c=='\'')
printf(";");
if (c=='X')
printf("Z");
if (c=='C')
printf("X");
if (c=='V')
printf("C");
if (c=='B')
printf("V");
if (c=='N')
printf("B");
if (c=='M')
printf("N");
if (c==',')
printf("M");
if (c=='.')
printf(",");
if (c=='/')
printf(".");
if (c==' ')
printf(" ");
if (c=='\n')
printf("\n");
}
return 0;
}
UVA 10370 | | Above Average
#include<stdio.h>
int main()
{
float total=0,count=0,a[1001],avrg=0,stdnt=0;
int i , t;
scanf("%d",&t);
while(t--){
scanf("%f",&stdnt);
for(i=0; i<stdnt; i++){
scanf("%f",&a[i]);
total+=a[i];
}
avrg=total/stdnt;
for(i=0; i<stdnt; i++){
if(a[i]>avrg)
count++;
}
printf("%.3f%%\n",(count*100)/stdnt);
total=0;
count=0;
}
return 0;
}
int main()
{
float total=0,count=0,a[1001],avrg=0,stdnt=0;
int i , t;
scanf("%d",&t);
while(t--){
scanf("%f",&stdnt);
for(i=0; i<stdnt; i++){
scanf("%f",&a[i]);
total+=a[i];
}
avrg=total/stdnt;
for(i=0; i<stdnt; i++){
if(a[i]>avrg)
count++;
}
printf("%.3f%%\n",(count*100)/stdnt);
total=0;
count=0;
}
return 0;
}
UVA 10346 | | Peter's Smokes
#include<bits/stdc++.h> using namespace std; int main() { long long n , k ,total=0, rest=0; while(cin>>n>>k){ total=n; while(n>=k){ rest=n%k; total+=(n/k); n=rest+(n/k); } cout<<total<<endl; } return 0; }
UVA 382 | | Perfection
#include<stdio.h>
int main()
{
long long i , j, x, sum=0;
printf("PERFECTION OUTPUT\n");
while(scanf("%lld",&x)==1){
if(x==0)
break;
else{
for(i=1; i<x; ++i){
if(x%i==0)
sum+=i;
}
if(sum==x)
printf("%5lld PERFECT\n",x);
else if(sum<x)
printf("%5lld DEFICIENT\n",x);
else if(sum>x)
printf("%5lld ABUNDANT\n",x);
}
sum=0;
}
printf("END OF OUTPUT\n");
return 0;
}
int main()
{
long long i , j, x, sum=0;
printf("PERFECTION OUTPUT\n");
while(scanf("%lld",&x)==1){
if(x==0)
break;
else{
for(i=1; i<x; ++i){
if(x%i==0)
sum+=i;
}
if(sum==x)
printf("%5lld PERFECT\n",x);
else if(sum<x)
printf("%5lld DEFICIENT\n",x);
else if(sum>x)
printf("%5lld ABUNDANT\n",x);
}
sum=0;
}
printf("END OF OUTPUT\n");
return 0;
}
UVA 10783 | | Odd Sum
#include<cstdio>
int main()
{
int a,b,j=1,t,i=0,sum;
scanf(“%d”,&t);
while (j<=t)
{
scanf(“%d %d”,&a,&b);
{
sum=0;
for (i=a;i<=b;i++)
if (i%2!=0)
sum+=i;
printf(“Case %d: %d\n”,j,sum);
}
}
}
{
int a,b,j=1,t,i=0,sum;
scanf(“%d”,&t);
while (j<=t)
{
scanf(“%d %d”,&a,&b);
{
sum=0;
for (i=a;i<=b;i++)
if (i%2!=0)
sum+=i;
printf(“Case %d: %d\n”,j,sum);
}
}
}
UVA 12372 | | Packing for Holiday
#include<bits/stdc++.h> using namespace std; int main() { int a , b , c,t,cse=0; cin>>t; while(t--){ cin>>a>>b>>c; if(a>20||b>20||c>20) cout<<"Case "<<++cse<<": "<<"bad"<<endl; else cout<<"Case "<<++cse<<": "<<"good"<<endl; } return 0; }
UVA 11547 | | Automatic Answer
#include<bits/stdc++.h> long long doshok(long long x); using namespace std; int main() { long long x,total=0,t,print=0; cin>>t; while(t--){ cin>>x; total=(((((x*567)/9)+7492)*235)/47)-498; if(total<0) total*=(-1); print=doshok(total); cout<<print<<endl; } return 0; } long long doshok(long long x){ long long num=x , digit=0; num/=10; digit=num%10; return(digit); }
Subscribe to:
Posts (Atom)