I think it's easy problem and must be rated 30 import java.util.Scanner; public class javasucc { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int h = 2, s = 10; for(int i=0; i<n; i++) { int a = in.nextInt(); String b = in.next(); if(b=="hungry"){ if(a>h) {h = a;} } else if(b=="satisfied"){ if(a<s) {s = a;} } } if(h >= s) System.out.println("Inconsistent"); else System.out.println(s); } } and the problem is that program doesn't want to do if and i can't change s to a 1) I wasn't crying for help though but just was wondering why 2) Thanks for the link, the problem was actually in "==" #include <iostream> #include <string> using namespace std; int main() { int hun = 2, sat = 10, n; cin >> n; string s; for (int i = 0, num; i < n; i++) { cin >> num >> s; if (s == "hungry") if (num > hun) hun = num; if (s == "satisfied") if (num < sat) sat = num; } if (hun >= sat) cout << "Inconsistent"; else cout << sat; } Give tests, please!! try: 2 4 satisfied 5 hungry You are so awesome, that I want to become your girlfriend, pleeeeease marry me!!!!!!!!!!!!!! Whos use => ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); => Need to delete, for the solve this problem. I think its a problem #CheckerMechanism [delete] Edited by author 23.06.2015 16:37 Edited by author 23.06.2015 16:37 import java.util.Scanner; public class T_1644 { public static void main(String[] args) { Scanner sc= new Scanner(System.in); int n=sc.nextInt(); int min=10; int max=Integer.MIN_VALUE; for (int i = 0; i < n; i++) { int x=sc.nextInt(); String s=sc.next(); if(s.equals("hungry"))max=Math.max(x, max); else min=Math.min(min,x); } if(max<min) System.out.println(min); else System.out.println("Inconsistent"); } } Messages should not contain correct solutions. i use 2 TreeSet<Integer>, nope, ok nope is prepopulated with 2, ok is prepopulated with 10 in cycle i read counts into one of them with checking if other one does not contain new value has been read recently if nope.last()>=ok.first() then the result is ok.first() nope.last>=ok.first ("g" instead of "ge" because they are never equal) var i,j,k,n,d,l:longint; st:string; s:array [1..100] of string; a:array [1..100] of integer; begin readln (n); if n=0 then writeln ('10'); k:=0; st:=''; for j:=1 to n do begin readln (k,st); a[j]:=k; s[j]:=st; end; for l:=1 to n-1 do for i:=1 to n-l do begin if a[i]<a[i+1] then begin k:=a[i]; a[i]:=a[i+1]; a[i+1]:=k; st:=s[i]; s[i]:=s[i+1]; s[i+1]:=st; end; end; i:=1; if s[1]=' satisfied' then begin while s[i]=' satisfied' do begin i:=i+1; k:=a[i-1]; end; writeln (k); end; d:=1; if s[1]=' hungry' then begin for i:=2 to n do begin if s[1]=s[i] then inc(d); end; if d= n then writeln ('10') else writeln ('Inconsistent'); end; end. can you give some tests? Edited by author 20.01.2009 14:17 try this: 2 5 hungry 5 satisfied (answer is "Inconsistent") People, can u help with test #3? I'm receiving WA... "It is known as a fact, that ten walnuts is always enough and two walnuts are always not enough." thanks!! that helped me!! I make the same mistake too. It is never too careful to read the question. Good luck! :) i agree you.can it done with 0.015s? i have 0.031
Edited by author 23.01.2013 16:55 Edited by author 23.01.2013 16:55 Is there a way to just get the first character of the type of experiment? (Like, if it is "hungry" just receive the "h" and ignore the rest) Why can't you use string and only judge the string[0]? #include <iostream> #include <string> #include <algorithm> #include <vector> using namespace std; int main() { int n; cin >> n; vector<int> ivec; vector<string> svec; int val; string s; for (int i = 0; i < n; ++i) { cin >> val; ivec.push_back(val); cin >> s; svec.push_back(s); } if (n == 0) { cout << 10 <<endl; return 0;} if (n == 1) { if (svec[0] == "satisfied") { cout << ivec[0] << endl; return 0;} if (svec[0] == "hungry") { cout << 10 << endl; return 0;} } int hungry[100]={0},satisfied[100]={0}; int hungry_num=0,satisfied_num=0; for (int i = 0; i < n; ++i) { if (svec[i] == "hungry") { hungry[hungry_num++] = ivec[i]; } if (svec[i] == "satisfied") { satisfied[satisfied_num++] = ivec[i]; } } sort(hungry, hungry+hungry_num); sort(satisfied, satisfied+satisfied_num); if (hungry[hungry_num-1] >= satisfied[0]) { cout << "Inconsistent" << endl; return 0; } cout << satisfied[0] << endl; return 0; } When n == 0; What is the answer? if n==0 answer is 10 Edited by author 24.09.2012 21:58 if you have only one experiments "X satisfied" then the answer is always X if you have only one experiments "X hungry" then the answer is always 10 If n == 0 ? What is the anwaer? Somebody already answered this in the discussion, it's 10 Edited by author 14.05.2012 00:31 #include <iostream> #include <string.h> using namespace std; void main() { int exp = 0; char fast[10]; int optimal = 0; int no_optimal = 0; int gorih; cin >> exp; for(int i = 1; i <= exp; i++) { cin >> gorih; cin>>fast; if(!strcmp(fast,"satisfied")) { if(optimal > gorih) { optimal = gorih;}if(optimal == 0){optimal=gorih;}} else {if(no_optimal==0){no_optimal=gorih;}if(no_optimal<gorih){no_optimal=gorih;}} } if(optimal == 0){cout<<"Inconsistent";} else if(optimal>no_optimal){ cout<<optimal;} else {cout<<"Inconsistent";} } It is known as a fact, that ten walnuts is always enough and two walnuts are always not enough. Hi. I've got WA on test 15. Here is my C code: /** * No: 1644 */ #include <stdio.h> #include <conio.h> #include <string.h> int main() { int n, i, a[101][2]={0}, maxs=0, mins=10, maxh=0; char s[15]; scanf("%d", &n); for(i=0; i<n; i++) { scanf("%d%s", &a[i][0], &s); if(strcmp(s, "satisfied") == 0) a[i][1] = 1; }
for(i=0; i<n; i++) if(a[i][1] == 1) { if(maxs < a[i][0]) maxs = a[i][0]; if(mins > a[i][0]) mins = a[i][0]; } else { if(maxh < a[i][0]) maxh = a[i][0]; }
if(maxs==0 && mins==10) printf("10"); else if(maxh >= maxs) printf("Inconsistent"); else { for(i=0; i<n; i++) if(a[i][0] > maxh && a[i][1] == 1 && maxs > a[i][0]) maxs = a[i][0]; printf("%d", maxs); }
return 0; } Edited by author 15.03.2012 16:34 [deleted] Edited by author 22.01.2012 11:33 |
|