Black Square (431A - Black Square)

431A - Black Square


Complexity 0(n)


  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4.  
  5. int a,b,c,d;
  6. string s;
  7. cin>>a>>b>>c>>d;
  8. cin>> s;
  9. int j=0,k=0,l=0,m=0;
  10.  
  11. for(int i=0;i<s.length();i++){
  12. if(s[i]=='1') j++;
  13. if(s[i]=='2') k++;
  14. if(s[i]=='3') l++;
  15. if(s[i]=='4') m++;
  16.  
  17. }
  18.  
  19. cout<<a*j+b*k+c*l+d*m;
  20.  
  21. }

Comments

Popular posts from this blog

Codeforce Problem 1703A. YES or YES?

Aptitude test assistant programmer 2018

1041A. Heist solution