Code: Select all
Before post anything u must read the previous posts carefully....
p.s. i use char & modify the char value by adding 128 before using it as a array index. I think u already saw it.
Moderator: Board moderators
Code: Select all
Before post anything u must read the previous posts carefully....
Code: Select all
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define MAX 15000
int main()
{
int test;
int nc;
unsigned char ch;
float sum=0.0;
char str[MAX];
long int x,j,i;
float val[MAX]={0};
long int nl;
int p;
cin>>test;
for(i=0;i<test;i++)
{
cin>>nc;
for(x=0;x<nc;x++)
{
cin>>ch>>val[int(ch)+256];
}
cin>>nl;
while(1)
{
if(nl<0)break;
gets(str);
for(p=0;p<strlen(str);p++)
{
sum+=val[(int(str[p])+256)];
}
nl--;
}
cout<<sum/100.00<<"$"<<endl;
sum = 0.0;
}
return 0;
}
Code: Select all
2
2
a 3
z 100
2
this is a test.
aaaaaaaaaaaaaa.
1
a 3
1
zero
Code: Select all
0.45$
0.00$
Code: Select all
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
using namespace std;
int costos[300];
int total;
int main(){
int casos;
cin >> casos;
for (int caso=0; caso< casos; caso++){
total=0;
for (int h=0; h<300 ; h++) costos[h]=0;
int k;
cin >> k;
unsigned char tempca;
int tempco;
for (int kk=0 ; kk<k ; kk++){
getchar();
tempca=getchar();
cin >> tempco;
costos[tempca]=tempco;
}
int lineas;
cin >> lineas;
string frase;
getline(cin , frase);
for (int linea=0;linea<lineas; linea++){
getline(cin , frase);
for (int o=0;o<frase.size() ; o++){
total+=costos[frase[o]];
}
}
double tempooo=total/100.0;
printf("%.2f$\n" , tempooo);
}
return 0;
}
Code: Select all
Forget it ...I got AC
Code: Select all
#include<stdio.h>
#include<string.h>
int val[300] ;
int c[300] ;
char s[10010] ;
int main()
{
int n , t , i , x ;
long long int res ;
char ch ;
// freopen("c:\\1.txt" , "r" , stdin) ;
scanf("%d\n" , &t) ;
while(t-- > 0)
{
scanf("%d" , &n) ;
gets(s) ;
memset(val , 0 , sizeof(val)) ;
memset(c , 0 , sizeof(c)) ;
while(n-- > 0)
{
ch = getchar() ;
scanf("%d" , &x) ;
gets(s) ;
val[ch + 128] = x ;
}
scanf("%d" , &n) ;
gets(s) ;
while(n-- > 0)
{
gets(s) ;
for(i = strlen(s) - 1 ; i >= 0 ; i--)
c[s[i] + 128]++ ;
}
for(i = 0 , res = 0 ; i < 300 ; i++)
res += (long long int)val[i] * c[i] ;
printf("%.2llf$\n" , (double)res / 100) ;
}
}
For this input......and "yy" number of cents with one leading zero if necessary.
Code: Select all
1
2
a 99
W 1
2
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzza
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzW
Code: Select all
1.00$
Code: Select all
1.0$
I am not agree with kbr_iut.....kbr_iut wrote:I told u to b careful about the output format
the problem says that:For this input......and "yy" number of cents with one leading zero if necessary.ur program gives.Code: Select all
1 2 a 99 W 1 2 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzza zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzW
correct output should beCode: Select all
1.00$
hope it will help.Code: Select all
1.0$
Code: Select all
cout<<res/100<<".";
printf("%02d$\n",res%100);
yes u r right. both of them are correct. I just did it according to the problem statement.I am not agree with kbr_iut.....
Output of above input will be 1.00$(may be 1.0$ also correct).
No need to use long long.
My output section which give me AC.
Code: Select all
cout<<res/100<<".";
printf("%02d$\n",res%100);
Code: Select all
#include<stdio.h>
#include<string.h>
#include<ctype.h>
char a[1000],c[150009][10009],d[10],e[10],q;
int main()
{
long n,i,m;
long b[1000],o,j,p,k,len,l,sum=0,y,z,x;
scanf("%ld",&n);
for(i=0;i<n;i++)
{
scanf("%ld",&m);
gets(e);
for(j=0;j<m;j++)
{
scanf("%c %ld",&a[j],&b[j]);
scanf("%c",&q);
}
scanf("%ld",&o);
scanf("%c",&q);
for(x=0;x<o;x++)
gets(c[x]);
sum=0;
for(j=0;j<m;j++)
{
p=0;
for(k=0;k<o;k++)
{
len=strlen(c[k]);
for(l=0;l<len;l++)
if(a[j]==c[k][l])
p++;
}
printf("%c %ld\n",a[j],p);
sum=sum+(p*b[j]);
printf("%ld\n",sum);
}
y=sum%100;
z=sum/100;
printf("%ld.%ld$",z,y);
printf("\n");
}
return 0;
}