#include<stdio.h> #include<string.h> int main() { int i,j,n,m,count,value,a,b,num[12],k,l,f,flag,s; while(scanf("%d%d",&n,&m)==2) { count=0; for(i=n;i<=m;i++) { value=i; flag=0; for(s=0;s<=9;s++) num[s]=0; while(value!=0) { a=value%10; b=value/10; value=b; if(num[a]==0) num[a]=1; else if(num[a]==1) { flag=1; break; } } if(flag!=1) count++; } printf("%d\n",count); } return 0; }
ACM Problem Solution : 12527 - Different Digits
Labels:
ACM
ACM Problem Solution : 12543 Longest Word
#include<stdio.h>
#include<string.h>
int main()
{
int i,j,k,l,len,max=0,kk,t;
char str[2000],ary[2000],maxstr[2000];
// freopen("F:\\a.txt","r",stdin);
while(scanf("%s",&str)==1)
{
if((str[0]=='E')&&(str[0]=='-')&&(str[0]=='N')&&(str[0]=='-')&&(str[0]=='D'))
break;
l=strlen(str);
kk=0;
for(j=0;j<l;j++)
{
if((str[j]>='A')&&(str[j]<='Z'))
ary[kk++]=str[j]+32;
else if((str[j]>='a')&&(str[j]<='z'))
ary[kk++]=str[j];
else if(str[j]=='-')
ary[kk++]=str[j];
}
ary[kk]='\0';
len=strlen(ary);
if(max<len)
{ max=len;
for(t=0;t<kk;t++)
maxstr[t]=ary[t];
maxstr[t]='\0';
}
}
printf("%s\n",maxstr);
return 0;
}
#include<string.h>
int main()
{
int i,j,k,l,len,max=0,kk,t;
char str[2000],ary[2000],maxstr[2000];
// freopen("F:\\a.txt","r",stdin);
while(scanf("%s",&str)==1)
{
if((str[0]=='E')&&(str[0]=='-')&&(str[0]=='N')&&(str[0]=='-')&&(str[0]=='D'))
break;
l=strlen(str);
kk=0;
for(j=0;j<l;j++)
{
if((str[j]>='A')&&(str[j]<='Z'))
ary[kk++]=str[j]+32;
else if((str[j]>='a')&&(str[j]<='z'))
ary[kk++]=str[j];
else if(str[j]=='-')
ary[kk++]=str[j];
}
ary[kk]='\0';
len=strlen(ary);
if(max<len)
{ max=len;
for(t=0;t<kk;t++)
maxstr[t]=ary[t];
maxstr[t]='\0';
}
}
printf("%s\n",maxstr);
return 0;
}
Labels:
ACM
12376
#include<stdio.h>
void findans(long int u);
long int j,adj[1000][1000],n,m,k,lp,total,test,t1,i,max=0,node;
long int LU[100002];
int main()
{
// int test,t1;
// freopen("F:\\a.txt","r",stdin);
scanf("%ld",&test);
for(t1=1;t1<=test;t1++)
{
total=0;
node=0;
scanf("%ld%ld",&n,&m);
for(lp=0;lp<n;lp++)
scanf("%ld",&LU[lp]);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
adj[i][j]=0;
}
}
for(k=0;k<m;k++)
{
scanf("%ld%ld",&i,&j);
adj[i][j]=1;
}
findans(0);
}
return 0;
}
void findans(long int u)
{
int ii,str;
max=0;
for(ii=0;ii<n;ii++)
{
if(adj[u][ii]==1)
{
if(LU[max]<LU[ii])
max=ii;
}
}
if(max!=0)
node=max;
if(max==0)
{
printf("Case %ld: ",t1);
printf("%ld %ld\n",total,node);
return;
}
total=total+LU[max];
findans(max);
}
void findans(long int u);
long int j,adj[1000][1000],n,m,k,lp,total,test,t1,i,max=0,node;
long int LU[100002];
int main()
{
// int test,t1;
// freopen("F:\\a.txt","r",stdin);
scanf("%ld",&test);
for(t1=1;t1<=test;t1++)
{
total=0;
node=0;
scanf("%ld%ld",&n,&m);
for(lp=0;lp<n;lp++)
scanf("%ld",&LU[lp]);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
adj[i][j]=0;
}
}
for(k=0;k<m;k++)
{
scanf("%ld%ld",&i,&j);
adj[i][j]=1;
}
findans(0);
}
return 0;
}
void findans(long int u)
{
int ii,str;
max=0;
for(ii=0;ii<n;ii++)
{
if(adj[u][ii]==1)
{
if(LU[max]<LU[ii])
max=ii;
}
}
if(max!=0)
node=max;
if(max==0)
{
printf("Case %ld: ",t1);
printf("%ld %ld\n",total,node);
return;
}
total=total+LU[max];
findans(max);
}
Labels:
ACM
ACM Problem Solution : 10945 - Mother bear
#include<stdio.h>
#include<string.h>
int main()
{
char str[10000],ary[10000];
int len,i,j,k,l,f;
// freopen("F:\\a.txt","r",stdin);
while(gets(str)!=NULL)
{
len=strlen(str);
if((len==4)&&(str[0]=='D')&&(str[1]=='O')&&(str[2]=='N')&&(str[3]=='E'))
break;
k=0;
for(i=0;i<len;i++)
{
if((str[i]>='a')&&(str[i]<='z'))
ary[k++]=str[i];
else if((str[i]>='A')&&(str[i]<='Z'))
ary[k++]=str[i]+32;
}
ary[k]='\0';
f=0;
for(j=0,l=k-1;(j<len&&l>=0);j++,l--)
{
if(ary[j]!=ary[l])
{
f=1;
break;
}
}
if(f==1)
printf("Uh oh..\n");
else
printf("You won't be eaten!\n");
}
return 0;
}
#include<string.h>
int main()
{
char str[10000],ary[10000];
int len,i,j,k,l,f;
// freopen("F:\\a.txt","r",stdin);
while(gets(str)!=NULL)
{
len=strlen(str);
if((len==4)&&(str[0]=='D')&&(str[1]=='O')&&(str[2]=='N')&&(str[3]=='E'))
break;
k=0;
for(i=0;i<len;i++)
{
if((str[i]>='a')&&(str[i]<='z'))
ary[k++]=str[i];
else if((str[i]>='A')&&(str[i]<='Z'))
ary[k++]=str[i]+32;
}
ary[k]='\0';
f=0;
for(j=0,l=k-1;(j<len&&l>=0);j++,l--)
{
if(ary[j]!=ary[l])
{
f=1;
break;
}
}
if(f==1)
printf("Uh oh..\n");
else
printf("You won't be eaten!\n");
}
return 0;
}
Labels:
ACM
ACM Problem Solution : 11479 - Is this the easiest problem?
#include<stdio.h>
#include<stdlib.h>
int main()
{
long long int t,p,x,y,z,k,max,small,mid,l,f;
scanf("%lld",&t);
for(p=1;p<=t;p++)
{
scanf("%lld%lld%lld",&x,&y,&z);
small=y-z;
if(small<0)
small=-small;
max=y+z;
if(max<0)
max=-max;
f=0;
if((small<x)&&(x<max))
f=1;
if((x==y)&&(x==z)&&(f==1))
printf("Case %lld: Equilateral\n",p);
else if(((x==y)||(y==z)||(x==z))&&(f==1))
printf("Case %lld: Isosceles\n",p);
else if(((x!=y)&&(y!=z)&&(x!=z))&&(f==1))
printf("Case %lld: Scalene\n",p);
else
printf("Case %lld: Invalid\n",p);
}
return 0;
}
#include<stdlib.h>
int main()
{
long long int t,p,x,y,z,k,max,small,mid,l,f;
scanf("%lld",&t);
for(p=1;p<=t;p++)
{
scanf("%lld%lld%lld",&x,&y,&z);
small=y-z;
if(small<0)
small=-small;
max=y+z;
if(max<0)
max=-max;
f=0;
if((small<x)&&(x<max))
f=1;
if((x==y)&&(x==z)&&(f==1))
printf("Case %lld: Equilateral\n",p);
else if(((x==y)||(y==z)||(x==z))&&(f==1))
printf("Case %lld: Isosceles\n",p);
else if(((x!=y)&&(y!=z)&&(x!=z))&&(f==1))
printf("Case %lld: Scalene\n",p);
else
printf("Case %lld: Invalid\n",p);
}
return 0;
}
Labels:
ACM
ACM Problem Solution : 11878 - Homework Checker
#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
int a,b,c,count=0,len,p,n,l1,q,n1;
char ch1,ch2;
char r[2000];
while(scanf("%d%c%d%c%s",&a,&ch1,&b,&ch2,&r)==5)
{
n=0;
if((r[0]>='0')&&(r[0]<='9'))
{
len=strlen(r);
q=0;
n=0;
for(l1=len-1;l1>=0;l1--)
{
n1=(r[l1]-48);
n=n+(n1*pow(10,q++));
}
if(ch1=='+')
{
if(a+b==n)
count++;
}
if(ch1=='-')
{
if(a-b==n)
count++;
}
}
else ;
}
printf("%d\n",count);
return 0;
}
#include<string.h>
#include<math.h>
int main()
{
int a,b,c,count=0,len,p,n,l1,q,n1;
char ch1,ch2;
char r[2000];
while(scanf("%d%c%d%c%s",&a,&ch1,&b,&ch2,&r)==5)
{
n=0;
if((r[0]>='0')&&(r[0]<='9'))
{
len=strlen(r);
q=0;
n=0;
for(l1=len-1;l1>=0;l1--)
{
n1=(r[l1]-48);
n=n+(n1*pow(10,q++));
}
if(ch1=='+')
{
if(a+b==n)
count++;
}
if(ch1=='-')
{
if(a-b==n)
count++;
}
}
else ;
}
printf("%d\n",count);
return 0;
}
Labels:
ACM
Subscribe to:
Posts (Atom)