Page 3 of 8
Still not working...
Posted: Mon Dec 26, 2005 3:00 am
by xintactox
I changed the line
cur_word.clear();
by
cur_word = ''";
It compiled and worked fine in my pc under g++ and cygwin, but i'm still getting CE... any suggestions?!
Thanks!
Posted: Mon Dec 26, 2005 8:43 am
by Jan
You used 2..
I believe you removed only one of them. Remove both of them. I m sure that you will not get CE.
Hope it helps.
Still CE... :(
Posted: Tue Dec 27, 2005 1:52 am
by xintactox
Hi!
I posted the following code, but I'm still getting CE...
I changed the lines you told me but.. it's not getting accepted... what else an be wrong?
Thank you
Code: Select all
#include <string>
#include <iostream>
#include <ctype.h>
//#include <iomanip>
using namespace std;
int main()
{
string linha, cur_word;
int count, char_count;
while(getline(cin, linha))
{
count = 0;
char_count = 0;
cur_word = "";
while(char_count < linha.size())
{
while(isalpha(linha[char_count]) && char_count < linha.size())
{
cur_word += linha[char_count];
char_count++;
}
for(int i = 0; i < cur_word.size(); i++)
if(isalpha(cur_word[i]))
{
count++;
break;
}
cur_world = "";
char_count++;
}
cout<<count<<endl;
}
return 0;
}
Posted: Tue Dec 27, 2005 4:36 am
by chunyi81
Very careless typo in your code.
You declared the following variables in your code:
but further down in your code I see this:
How could I be so STUPID?!
Posted: Tue Dec 27, 2005 4:56 am
by xintactox
You we're right....
I was too stupid, im sorry for bothering u all!
Ang I Got AC! Thanks!
494
Posted: Mon Jan 09, 2006 3:18 pm
by abhi
this is my code i get WA .i think it should work ......where am i wrong??
Posted: Mon Jan 09, 2006 3:48 pm
by Schutzstaffel
At first glance your program doesn't give the correct output if the line starts with a character that's is not in A-Z and a-z like ponctuation and whitespace.
For example:
You program would output 6 wich is wrong.
Also you program didn't output the correct values for the example given because of this condition:
gets function fills the array only until the last character in str position, the rest of the array has garbage for so saying so you should have while (i < strlen(str)) instead.
Good luck, you're near the correct answer

Posted: Mon Jan 09, 2006 4:31 pm
by chunyi81
Did you even test your code with the sample input. Your code gives wrong answer with the sample input.
Change this:
to this:
Code: Select all
while(str[i] != '\0' && !isalpha(str[i])) i++;
This will make your code pass the sample input but your code will still give WA if the sample input contains one word like this:
Input:
a
Correct Output:
1
But your code gives:
0
Posted: Mon Jan 09, 2006 4:43 pm
by abhi
well i made the changes which Schutzstaffel suggested and got AC anyways . but still the time is 0.002 s. i dont know y it is so slow ????

Posted: Mon Jan 09, 2006 5:13 pm
by Jan
I have not read your code. Try submitting 2 or 3 times. I think you will get it Accepted in 0.000 seconds. Otherwise try to avoid printf. Then your runtime will decrease.
Posted: Mon Jan 09, 2006 7:28 pm
by abhi
well anyways ..... i checked on the web and according to C standards gets must terminate the string with a '\0' character. so if i use
then it should have worked properly i think ????
Posted: Mon Jan 09, 2006 8:27 pm
by mamun
abhi wrote:well anyways ..... i checked on the web and according to C standards gets must terminate the string with a '\0' character. so if i use
then
it should have worked properly i think ????
It should, depending on the value of i (I didn't get a chance to read your code

).
Posted: Tue Jan 10, 2006 5:36 am
by chunyi81
You had two while loops in your original code. The first one did this:
while(str != '\0')
This is fine of course.
It is the inner while loop that can cause problems:
while(!isalpha(str)) i++;
If str is '\0' in this loop your code will still increment i, since the null character is not an alphabet character according to the isalpha function.
494 - WA ?
Posted: Tue Jun 06, 2006 8:36 pm
by fixit
var a:array [0..100] of char;count,i:integer;
function ileslow(s:string):integer;
var k:integer;var slowo_start:boolean;counter:longint;
begin
slowo_start:=false;
counter:=0;
for k:=1 to length(s) do
if (s[k] in ['a'..'z']) or (s[k] in ['A'..'Z']) then
begin
if not slowo_start then
begin
inc(counter); slowo_start:=true;
end;
end else
slowo_start:=false;
ileslow:=counter;
end;
begin
count:=0;
while true do
begin
readln(a[count]);inc(count);
if (a[count-1][length(a[count-1])]=#26) or (a[count-1][1]=#26) then break;
end;
for i:=0 to count-1 do
writeln(ileslow(a
));
end.
I don't understand what is wrong 
reply to 494(fixit)
Posted: Thu Jun 15, 2006 11:18 am
by farzane
Hi dear fixit
First:you didn't say what kind of problem you had with your code.After submition what kind of error you recived.
Your algorithm for this problem is true for sure.I submitted a solution for this problem by this algoritm and I recived an ACCEPTED reply.
Here is my code in c++:
-----------------------------------------------
#include<iostream.h>
int counter(char str[]){
int count=0;
bool inword=false;
int i=0;
for(;str;i++)
if((str>='a' && str<='z')||(str>='A' && str<='Z')){
if(inword==false){
inword=true;
count++;
}
}
else inword=false;
return count;
}
void main(){
char str[100000];
while(cin.getline(str,100000))
cout<<counter(str)<<endl;
}
-------------------------------------------------------------------------
Try to correct your own code.
I saw some mistakes in your code:
1)You recived all of inputs and saved them and then solved each of them.
while you can read and solve them one by one why you did so?
2)I think the size of array a(100) is too small.
3)You define array a so: a:array [0..100] of char;
but you use it in a different model: a[count-1][length(a[count-1])]
(I mean the number of brakets[])
All of the above are my opinions and maybe they are wrong,but I hope I was helpful.
And at the end I excuse if I couldn't express myself good.English isn't my
tongue languge and I'm not good at it.
with the best regards