#include<cstdio> #include<cstring> using namespace std; int main() { int tc,c=1; scanf("%d",&tc); getchar(); while (tc--) { char s[1000]; gets(s); int l=strlen(s); int sum=0; for (int i=0;i<l;i++) switch(s[i]) { case 'b': case 'e': case 'h': case 'k': case 'n': case 'q': case 'u': case 'x': sum+=2; break; case 'c': case 'f': case 'i': case 'l': case 'o': case 'r': case 'v': case 'y': sum+=3; break; case 's': case 'z': sum+=4; break; default : sum+=1; break; } printf("Case #%d: %d\n",c++,sum); } return 0; }
Tuesday, July 19, 2016
Published July 19, 2016 by Sourav Chowdhury with 0 comment
Published July 19, 2016 by Sourav Chowdhury with 0 comment
#include<cstdio> using namespace std; long long int matrix[100][100]; bool is_symmetric(int n) { for (int i=0;i<n;i++) for (int j=0;j<n;j++) if (matrix[i][j]!=matrix[n-i-1][n-j-1]) return false; return true; } int main() { int tc,c=1; scanf("%d",&tc); while (tc--) { int n,flag=1; char ch1,ch2; getchar(); scanf("N = %d",&n); for (int i=0;i<n;i++) for (int j=0;j<n;j++) { scanf("%lld",&matrix[i][j]); if (matrix[i][j]<0) flag=0; } if (flag && is_symmetric(n)) printf("Test #%d: Symmetric.\n",c++); else printf("Test #%d: Non-symmetric.\n",c++); } return 0; }
Published July 19, 2016 by Sourav Chowdhury with 0 comment
#include<cstdio> #include<cstring> #include<cctype> using namespace std; int main() { char s[500],s1[500],c; while (gets(s)) { if (!strcmp(s,"DONE")) return 0; int l=strlen(s); int k=-1; for (int i=0;i<l;i++) { c=tolower(s[i]); if (c>='a' && c<='z') s1[++k]=c; } int flag=1; for (int i=0;i<k;i++,k--) { if (s1[i]!=s1[k]) { flag=0; break; } } if (flag) printf("You won't be eaten!\n"); else printf("Uh oh..\n"); } return 0; }
Monday, July 18, 2016
Published July 18, 2016 by Sourav Chowdhury with 0 comment
#include<cstdio> #include<cmath> using namespace std; typedef long long int lld; int main() { lld n,sum; while (scanf("%lld",&n)!=EOF) printf("%lld\n",n*n*(n+1)*(n+1)/4); return 0; }
Published July 18, 2016 by Sourav Chowdhury with 0 comment
#include<cstdio> #include<cstring> using namespace std; int main() { int tc,score,a[90]; char s[90]; scanf("%d",&tc); getchar(); while (tc--) { scanf("%s",s); int l=strlen(s); if (s[0]=='O')a[0]=1; else a[0]=0; score=a[0]; for (int i=1;i<l;i++) { if (s[i]=='O')a[i]=a[i-1]+1; else a[i]=0; score+=a[i]; } printf("%d\n",score); } return 0; }
Published July 18, 2016 by Sourav Chowdhury with 0 comment
#include <stdio.h> int main() { double h,u,d,f,climb; int day; while (scanf("%lf%lf%lf%lf",&h,&u,&d,&f)==4) { if (h==0) break; f=(u*f)/100; climb=u; day=1; while (1) { if (climb>h) { printf("success on day %d\n",day); break; } climb-=d; if (climb<0) { printf("failure on day %d\n",day); break; } u=u-f; if (u<0) u=0; climb+=u; day++; } } return 0; }
Published July 18, 2016 by Sourav Chowdhury with 0 comment
#include<cstdio> using namespace std; typedef long long int lld; lld t[100]={0}; lld total(int n) { if (n<0) return 0; if (t[n]==0) t[n]=total(n-2)+total(n-1)+1; return t[n]; } int main() { int n; t[0]=1; t[1]=2; while (scanf("%d",&n)==1) { if (n==-1) return 0; printf("%lld %lld\n",total(n-1),total(n)); } return 0; }
Subscribe to:
Posts (Atom)