Re: 10106 -Product
Posted: Mon Feb 24, 2014 2:07 pm
Replying to this thread so I can follow it. Thanks.
Code: Select all
Removed after AC
So, couple thingsRika71 wrote:why WA??? please help.thanks in advance
Code: Select all
while(scanf("%s%s",&s1,&s2)==2)
Code: Select all
while(scanf("%s%s",s1,s2) != EOF)
Code: Select all
int main(void)
Code: Select all
int main()
Code: Select all
char s1[1000],s2[1000],s3[40000][40000],s4[100000];
Code: Select all
1 2 3
Gotcha. Thanks for sharing. I didn't know this.brianfry713 wrote: See:
http://www.cplusplus.com/reference/cstdio/scanf/
I prefer using:
while(scanf("%s%s", s1, s2) == 2)
instead of:
while(scanf("%s%s", s1, s2) != EOF)
Will do.Try this input to see the difference:Code: Select all
1 2 3
Again, thank you for teaching me.Your third point is equivalent and just a matter of style.
Large arrays should be declared globally, static, or dynamic so they go on the heap instead of the stack.
Code: Select all
1063805700
972401858
Code: Select all
1034446639230990600
I did look at this but found no mention of what the "2" (specifically) is for. Is this related to the line?brianfry713 wrote: See:
http://www.cplusplus.com/reference/cstdio/scanf/
So, if we were reading in 3 inputs, for example, we'd replace the "2" by "3"?On success, the function returns the number of items of the argument list successfully filled.
OK. I got around to doing this. Here's what I wrote as a testI prefer using:
while(scanf("%s%s", s1, s2) == 2)
instead of:
while(scanf("%s%s", s1, s2) != EOF)
Try this input to see the difference:Code: Select all
1 2 3
Code: Select all
#include<bits/stdc++.h>
using namespace std;
#define SIZE 1000
int main() {
char s1[SIZE], s2[SIZE];
while(scanf("%s%s", s1, s2) != EOF) {
printf("s1: %s and s2: %s\n", s1, s2);
}
return 0;
}
Code: Select all
s1: 1 and s2: 2
s1: 3 and s2: 2
Code: Select all
s1: 1 and s2: 2
Oh great. Thanks for sharing.On my machine, Rika71's code compiles and runs on the sample input correctly as he or she wrote it.
So, the code compiles and builds fine. But when I run it on the following (sample) inputWhat was your compile error v1n1t? Were you not able to allocate enough memory for s3?
Code: Select all
12
12
2
222222222222222222222222
Code: Select all
Killed
A profusion of thanks to brianfry713.brianfry713 wrote:On my machine, Rika71's code compiles and runs on the sample input correctly as he or she wrote it. What was your compile error v1n1t? Were you not able to allocate enough memory for s3? However if I move those large arrays inside of main then I get a seg fault on execution.