Greetings!.Subeen wrote:7
too high
3
too high
7
too high
6
too high
7
too high
7
too high
6
right on
What's the Output for this code??.
Thanks in advance.
Moderator: Board moderators
Greetings!.Subeen wrote:7
too high
3
too high
7
too high
6
too high
7
too high
7
too high
6
right on
The initial value of high must be 11.Frostina wrote:I try all the test datas
but my code is still wrong
plz help..
[c]#include <stdio.h>
int main(void) {
int n, ans, high = 10, low = 0;
char dir[20];
while (scanf("%d",&n)==1) {
if (!n) break;
scanf(" %[^\n]", dir);
if (!strcmp(dir,"too high"))
if (n<high) high = n;
if (!strcmp(dir,"too low"))
if (n>low) low = n;
if (!strcmp(dir,"right on")) {
if (n>=high||n<=low)
puts("Stan is dishonest");
else puts("Stan may be honest");
high = 10;
low = 0;
}
}
return 0;
}
[/c]
#include <cstdio>
#include <cstring>
using namespace std;
int main (void)
{
int number, h = 11, l = 0;
char word[20];
while (scanf("%d", &number))
{
if (number == 0) break;
scanf("%[^\n]", word);
if (strcmp(word, "too high") == 0)
{
if (number < h) h = number;
}
if (strcmp(word, "too low") == 0)
{
if (number > l) l = number;
}
if (strcmp(word, "right on") == 0)
{
if (number >= h || number <= l) printf("Stan is dishonest\n");
else printf("Stan may be honest\n");
h = 10, l = 0;
}
}
return 0;
}
Code: Select all
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int a[20];
void makeTrue()
{
for(int i=1; i<=10; i++)
a[i]=1;
}
int testTrue()
{
for(int i=1; i<=10; i++)
{
if(a[i]==1)return 1;
}
return 0;
}
int main()
{
//freopen("10530.txt","r",stdin);
int N;
char NN[20];
char msg[20];
makeTrue();
while(scanf("%d\n",&N)==1 && N)
{
scanf("%[^\n]", msg);
if(strcmp(msg,"too high")==0)
{
for(int i=N; i<=10; i++)
{
a[i]=0;
}
}
else if(strcmp(msg,"too low")==0)
{
for(int i=N; i>=1; i--)
{
a[i]=0;
}
}
else if(strcmp(msg,"right on")==0)
{
if(testTrue())
{
printf("Stan may be honest\n");
}
else
{
printf("Stan is dishonest\n");
}
makeTrue();
}
}
return 0;
}
Code: Select all
5
too low
5
right on
0
Code: Select all
........
else if(strcmp(msg,"right on")==0)
{
if(testTrue() && a[N])
{
printf("Stan may be honest\n");
}
else
{
printf("Stan is dishonest\n");
}
makeTrue();
}
............
Code: Select all
10
too high
3
too low
4
too high
2
right on
5
too low
7
too high
6
right on
9
too low
8
too low
7
too low
10
right on
7
too high
7
right on
1
too low
2
too high
3
right on
3
too high
8
too high
1
too low
2
right on
5
right on
10
too low
9
too high
6
right on
0
Code: Select all
Stan is dishonest
Stan may be honest
Stan may be honest
Stan is dishonest
Stan is dishonest
Stan may be honest
Stan may be honest
Stan is dishonest
Code: Select all
10
too high
3
too low
4
too high
2
right on
5
too low
7
too high
6
right on
9
too low
8
too low
7
too low
10
right on
7
too high
7
right on
1
too low
2
too high
3
right on
3
too high
8
too high
1
too low
2
right on
5
right on
10
too low
9
too high
6
right on
8
right on
9
too low
8
too low
7
too low
8
right on
5
too low
5
right on
0
Code: Select all
Stan is dishonest
Stan may be honest
Stan may be honest
Stan is dishonest
Stan is dishonest
Stan may be honest
Stan may be honest
Stan is dishonest
Stan may be honest
Stan may be honest
Stan is dishonest
Code: Select all
9
too low
8
too low
7
too low
8
right on
Code: Select all
Stan is dishonest
Stan may be honest
Stan may be honest
Stan is dishonest
Stan is dishonest
Stan may be honest
Stan may be honest
Stan is dishonest
Stan may be honest
Stan is dishonest
Stan is dishonest
Code: Select all
7
too low
8
too high
9
right on
1
too high
7
too low
8
right on
5
too low
8
too high
7
too high
5
right on
10
right on
10
too low
1
too high
5
right on
4
too high
3
too high
5
right on
6
too low
7
too low
5
right on
4
too low
1
too low
6
too high
9
too high
5
right on
1
too low
1
right on
10
too high
10
right on
5
too low
8
too high
7
too high
6
too high
5
too low
6
right on
0
Code: Select all
Stan is dishonest
Stan is dishonest
Stan is dishonest
Stan may be honest
Stan is dishonest
Stan is dishonest
Stan is dishonest
Stan may be honest
Stan is dishonest
Stan is dishonest
Stan is dishonest