10176 - Ocean Deep ! - Make it shallow !!

All about problems in Volume 101. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Jehad Uddin
Learning poster
Posts: 74
Joined: Fri May 08, 2009 5:16 pm

Re: 10176 - Ocean Deep! Make it shallow!!

Post by Jehad Uddin »

got acc after a long time,
input processing was wrong actually.
rmg_91
New poster
Posts: 2
Joined: Thu Jan 26, 2012 8:22 am

Re: 10176 - Ocean Deep! Make it shallow!!

Post by rmg_91 »

Why this code generate WA ,could anybody give some test cases?

Code: Select all

#include<cstdio>
#include<string>
#include<iostream>
#define mod 131071
using namespace std;

void doit(string s){
	int sol=0;
	for(int i=0;i<s.length();i++){
		sol*=2;
		sol%=mod;
		sol=(sol+(int)(s[i]-'0'))%mod; 
	}
	sol%=mod;
	if(sol==0)puts("YES");
	else puts("N0");
}

int main(){
	string s,cad="";
	while(cin>>s){
		if(s[s.length()-1]=='#'){
			doit(cad+s.substr(0,s.length()-1));
			cad="";
		}
		else cad+=s;	
	}
}

rmg_91
New poster
Posts: 2
Joined: Thu Jan 26, 2012 8:22 am

Re: 10176 - Ocean Deep! Make it shallow!!

Post by rmg_91 »

I found my mistake !!
X123
New poster
Posts: 11
Joined: Fri Oct 04, 2013 1:28 am

Re: 10176 - Ocean Deep! Make it shallow!!

Post by X123 »

i am getting WA ,,, but failed to find out what is the wrong!! :roll:


#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
char str[20000],temp[20000];
int i,j=0;
while(scanf("%c",&str[0])==1)
{
j=0;
int p=0;
if(str[0]!=' '&&str[0]!='\n'){
temp[j]=str[0];
j++;
}
for(i=1;i>=0;i++)
{
scanf("%c",&str);
if(str=='#'){
temp[j]='\0';
break;
}
if(str!=' '&&str!='\n'){
temp[j]=str;
j++;
}
}
int l=strlen(temp);
for(i=0;i<l;i++)
{
int k=(temp-48)+p*2;
p=k%131071;
}
if(p==0)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}

plz help :-?
Many of life’s failures are people who did not realize how close they were to success when they gave up.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10176 - Ocean Deep! Make it shallow!!

Post by brianfry713 »

It looks like you figured it out
Check input and AC output for thousands of problems on uDebug!
Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 10176 - Ocean Deep ! - Make it shallow !!

Post by Shahidul.CSE »

Got Accepted
Last edited by Shahidul.CSE on Tue Nov 18, 2014 7:53 am, edited 1 time in total.
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10176 - Ocean Deep ! - Make it shallow !!

Post by brianfry713 »

At each step as you convert the binary string to a decimal value do a modulus 131071.
Check input and AC output for thousands of problems on uDebug!
seddik11
New poster
Posts: 2
Joined: Sat Apr 25, 2015 6:01 pm

Re:

Post by seddik11 »

Dominik Michniewski wrote:I use Finite State Automaton to solve this problem.

Best regards
DM
very efficient way to use automate i just wrote 2 lines and got accepted really interesting !
Post Reply

Return to “Volume 101 (10100-10199)”