Страница 2 I think it's easy problem and must be rated 30 #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; } 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 "==" 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 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) 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"); } } 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 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. 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 Страница 1 Why? #include <iostream> #include <string> using namespace std; int main() { int hun[100],sat[100],N,maxhun=0,minsat=0; cin>>N; int numhun=0,numsat=0; for(int i=0;i<N;i++) { int temp; string lol; cin>>temp>>lol; if(lol=="hungry") { hun[numhun]=temp; ++numhun; } else { sat[numsat]=temp; ++numsat; } } for(int i=1;i<numhun;i++) if(hun[i]>hun[maxhun]) maxhun=i; for(int i=1;i<numsat;i++) if(sat[i]<sat[minsat]) minsat=i; if(numsat==0 || N==0) cout<<10; else if(hun[maxhun]>=sat[minsat]) cout<<"Inconsistent"; else cout<<sat[minsat]; } I got AC. I just replace read(n) to readln(n). Why it condition do WA? And if i use string instead string[11] i have compilation error. WTF? Edited by author 05.12.2011 02:14 Edited by author 23.09.2011 20:23 |
|