Code: Select all
Moderator: Board moderators
Code: Select all
Code: Select all
#include<stdio.h>
int main()
{
char s[103];
int i,cnt,tc,n;
scanf("%d",&tc);
n=1;
while(tc>0)
{
fflush(stdin);
gets(s);
cnt=0;
for(i=0;s[i];i++)
{
if(s[i]=='a' || s[i]=='d' || s[i]=='g' || s[i]=='j' || s[i]=='m' || s[i]=='p' || s[i]=='t' || s[i]=='w' || s[i]==' ')
{
cnt+=1;
}
else if(s[i]=='b' || s[i]=='e' || s[i]=='h' || s[i]=='k' || s[i]=='n' || s[i]=='q' || s[i]=='u' || s[i]=='x')
{
cnt+=2;
}
else if(s[i]=='c' || s[i]=='f' || s[i]=='i' || s[i]=='l' || s[i]=='o' || s[i]=='r' || s[i]=='v' || s[i]=='y')
{
cnt+=3;
}
else if(s[i]=='s' || s[i]=='z')
{
cnt+=4;
}
}
printf("Case #%d: %d\n",n,cnt);
n++;
tc--;
}
return 0;
}
shamim wrote:Just add a dummy gets after you take the number of cases as input and remove the fflush().
This should get your code AC
Code: Select all
thanks a lot.........
Code: Select all
keep dreaming...
Code: Select all
# include <iostream>
# include <string>
using namespace std;
int main()
{
int t,c = 0;
cin>>t;
//do something here
fflush(stdin);
string inp;
while(t--)
{
getline(cin,inp);
//do something here
cout<<"Case #"<<++c<<": "<<res<<endl;
}
return 0;
}
Code: Select all
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int n[26]={1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,4,1,2,3,1,2,3,4};
char b[150];
int a=0,t;
cin>>t;
for(int j=0;j<t;j++)
{
a=0;
getchar();
gets(b);
for(int i=0;b[i];i++)
{
if(b[i]==32)
a++;
else
a+=n[b[i]-'a'];
}
cout<<"Case #"<<j<<": "<<a<<endl;
}
return 0;
}
Code: Select all
cout<<"Case #"<<j<<": "<<a<<endl;
Code: Select all
cout<<"Case #"<<j+1<<": "<<a<<endl;
Code: Select all
#include <stdio.h>
int main()
{
int test;
char str[100];
scanf("%d",&test);
//fflush(stdin);
for(int i=0;i<test;i++)
{
gets(str);
int j=0,count=0;
while(str[j]!='\0')
{
if(str[j]==' ')count+=1;
else if(str[j]=='a' || str[j]=='d' || str[j] == 'g' || str[j] =='j' || str[j]=='m' || str[j] == 'p' || str[j] == 't' || str[j] =='w')count+=1;
else if(str[j]=='b' || str[j]=='e' || str[j] == 'h' || str[j] =='k' || str[j]=='n' || str[j] == 'q' || str[j] == 'u' || str[j] =='x')count+=2;
else if(str[j]=='c' || str[j]=='f' || str[j] == 'i' || str[j] =='l' || str[j]=='o' || str[j] == 'r' || str[j] == 'v' || str[j] == 'y')count+=3;
else count+=4;
j++;
}
printf("Case %d: %d\n",i+1,count);
}
return 0;
}
Hello samin
change this lineToCode: Select all
printf("Case %d: %d\n",i+1,count);
Code: Select all
printf("Case #%d: %d\n",i+1,count);