Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения | Страница 1 | why compilation error? | Iskandar | 1585. Пингвины | 24 фев 2012 21:41 | 1 | #include<iostream> #include<string.h> #include<stdio.h> using namespace std; int main() {string z[10000],str,a1="Emperor",a2="Little", a3="Macaroni"; int n,i,j,k,a=0,b=0,c=0; cin>>n; for(i=0;i<n;i++) {cin>>z[i]>>str; if(z[0]==a1)a++; if(z[0]==a2)b++; if(z[0]==a3)c++; } if(a>b&&a>c){cout<<"Emperor Penguins";} else if(b>a&&b>c){cout<<"Little Penguins";} else cout<<"Macaroni Penguins"; return 0; } | why crash? | tikuna_147 | 1585. Пингвины | 12 фев 2012 20:58 | 1 | why crash? help me. Edited by author 12.02.2012 20:58 Edited by author 12.02.2012 20:58 | WA4 | sftuit | 1585. Пингвины | 19 апр 2012 12:18 | 3 | WA4 sftuit 19 окт 2011 11:15 Help me to find a mistake, please var i,j,k,n,s:byte; ping:array[1..1001] of string; begin i:=0;j:=0;k:=0; readln(n); for s:=1 to n do begin readln(ping[s]); if ping[s]='Emperor Penguin' then i:=i+1 else if ping[s]='Macaroni Penguin' then k:=k+1 else if ping[s]='Little Penguin' then j:=j+1; end; if (j>i) and (j>k) then writeln('Little Penguin'); if (k>i) and (k>j) then writeln('Macaroni Penguin'); if (i>k) and (i>j) then writeln('Emperor Penguin'); end. is a Byte going to be big enough to store the number of penguins of each type? | WA#6 on Byte by Byte stream reading | d3m0n1c | 1585. Пингвины | 11 окт 2011 20:12 | 1 | probably test6 contains unnecessary characters Edited by author 12.10.2011 19:07 | Test1 | Abbath1349 | 1585. Пингвины | 11 окт 2011 19:52 | 1 | Test1 Abbath1349 11 окт 2011 19:52 | Why WA??? Why??? | Whiteha | 1585. Пингвины | 2 окт 2011 15:24 | 1 | #include <iostream> #include <cmath> using namespace std; char **ms; int n, EP, LP, MP, A; int main() { cin >> n; ms = new char* [n]; for (int i = 0; i < n; ++i) { ms[i] = new char [30]; } for(int i = 0; i < n; ++i) { cin.sync(); //cin.getline(ms[i], 28); cin >> ms[i]; } for(int i = 0; i < n; ++i) { if (!(strcmp(ms[i], "Emperor"))) EP++; if (!(strcmp(ms[i], "Little"))) LP++; if (!(strcmp(ms[i], "Macaroni"))) MP++; } A = max(EP, LP); A = max(A, MP); if (A == EP)cout << "Emperor Penguin" << endl; if (A == LP)cout << "Little Penguin" << endl; if (A == MP)cout << "Macaroni Penguin" << endl; return 0; } Edited by author 02.10.2011 15:29 | Help Me! | TiMiD | 1585. Пингвины | 12 авг 2011 12:54 | 3 | Hello! Where here mistake? Prompt please, at all there does not pass 1 test, and at itself in the compiler passes. var s:array[1..1000] of string; i,n,z,x,m,l:integer; begin read(n); z:=0;m:=0;l:=0; for i:=1 to n do begin read(s[i]); if s[i]='Emperor Penguin' then z:=(z+1); if s[i]='Little Penguin' then m:=(m+1); if s[i]='Macaroni Penguin' then l:=(l+1); end; if (z>=m) and (z>=l) then write('Emperor Penguin'); if (m>=z) and (m>=l) then write('Little Penguin'); if (l>=z) and (l>=m) then write('Macaroni Penguin'); end. try to use readln instead read and use > instead >= Edited by author 12.08.2011 01:43 2 hatred : so too does not pass | If you got WA3 | smolcoder | 1585. Пингвины | 21 сен 2011 01:19 | 2 | For C++: getline(cin, s) ---> cin >> s1 >> s2; s1 += " " + s2; | Wrong tests | LostInSpace | 1585. Пингвины | 29 июл 2011 15:30 | 2 | I think, test cases violates the condition. for example in input stream presents empty strings, or strings with other world except pinguins types. but in condition we can see that "In each of the next" and "which is one of the following: “Emperor Penguin,” “Little Penguin,” and “Macaroni Penguin.” " in russian Я думаю что проверочные тесты нарушают условия задачи например присутствуют пустые строки или слова отличные от видов пингвинов. Хотя в условии говорится что "В каждой из следующих n строк записано по одному виду пингвинов. Среди видов встречаются только «Emperor Penguin», «Little Penguin» и «Macaroni Penguin». " This program says that the tests are correct. #include <cstdio> #include <string> using namespace std; string s, a[3] = {"Emperor Penguin", "Little Penguin", "Macaroni Penguin"}; char _s[100]; int n,c[3]; void getml() { int *a = new int[100000]; getml(); } int main() { scanf("%d", &n); gets(_s); if( _s[0] ) getml();; while(n--) { gets(_s); s = _s; for(int i=0;i<4;++i) { if( i == 3 ) getml(); if( a[i] == s ) { ++c[i]; break; } } } int m = 0; if( c[m] < c[1] ) m = 1; if( c[m] < c[2] ) m = 2; printf("%s",a[m].c_str()); return 0; } | Why Crash? | Georgeek | 1585. Пингвины | 5 июл 2011 14:40 | 1 | import java.util.Scanner; public class Example { private static int n; private static String[] penguin; private static int[] myCount = {1, 1, 1}; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); n = scanner.nextInt(); if(n>=1 && n<=1000){ scanner = new Scanner(System.in); penguin = new String[n]; for (int i = 0; i < n; i++) { penguin[i] = scanner.nextLine(); if (penguin[i].equals("Emperor Penguin")) { myCount[0]++; }else if (penguin[i].equals("Little Penguin")) { myCount[1]++; }else if (penguin[i].equals("Macaroni Penguin")) { myCount[2]++; } } if(myCount[0]>myCount[1]){ if(myCount[0]>myCount[2]){ System.out.println("Emperor Penguin"); }else{ System.out.println("Macaroni Penguin"); } }else if(myCount[1]>myCount[2]){ System.out.println("Little Penguin"); }else{ System.out.println("Macaroni Penguin"); }
} } } | Why crashing? | Manikandan | 1585. Пингвины | 5 сен 2012 12:21 | 2 | import java.io.*; import java.util.Scanner; public class string { public static void main(String args[]) throws IOException { Scanner sc = new Scanner(System.in); BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in)); String each; int m=0,l=0,e=0; int num = sc.nextInt(); for(int i=0;i<num;i++) { each = bufferedreader.readLine(); if(each.charAt(0)=='M') { m++; } else if(each.charAt(0)=='L') { l++; } else if(each.charAt(0)=='E') { e++; } } if((m>=l) && (m>=e)) System.out.println("Macaroni Penguin"); if((l>=m) && (l>=e)) System.out.println("Little Penguin"); if((e>=m) && (e>=l)) System.out.println("Emperor Penguin");
} Same question, maybe related with BufferedReader. Several times faced with this problem, any idea? | got AC at first try | Zhihua Lai | 1585. Пингвины | 28 апр 2012 19:11 | 3 | Edited by author 05.04.2010 05:23 | Why i got crash??? | Rudnev Vladimir | 1585. Пингвины | 23 фев 2010 00:32 | 4 | what's wrong??? var a:array[1..1000] of string;v,b,c,n,i:integer; begin b:=0;c:=0;v:=0; read(n); for i:=1 to n+1 do begin readln(a[i]); if a[i]='Emperor Penguin' then v:=v+1; if a[i]='Macaroni Penguin' then b:=b+1; if a[i]='Little Penguin' then c:=c+1; end; if (v>b)and(v>c)then writeln('Emperor Penguin'); if (b>v)and(b>c)then writeln('Macaroni Penguin'); if (c>b)and(c>v)then writeln('Little Penguin'); end. Why "for i:=1 to n+1 do"??? Must be "for i:=1 to n do"!!! if i do "for i:=1 to n do" then (не знаю как дальше поанглийски) Короче он вводит на 1 меньше Change "read(n)" to "readln(n)". | Help me to find a mistake please! | RoskaTa | 1585. Пингвины | 5 июл 2008 20:58 | 3 | This is my source [code deleted] What is wrong? I can't find any mistakes but i always get WA! Please Help me to find my mistake! Thank you! Edited by author 03.07.2008 00:29 Edited by author 05.07.2008 20:59 there are many notes which may help you make your code CLEANer and finding your mistake: 1. use scanf("%d\n",&n) instead of cin>>n (because there cin will not read the '\n' and it will be read by getline) 2.This part may be shortened for(j=0;j<sz;j++) { if(j==0&&s[j]=='L')br++; else if(j==0&&s[j]=='M')br1++; else if(j==0&&s[j]=='E')br2++; } INSTEAD: if(s[j]=='L')br++; else if(s[j]==.... 3. and do not bother yourself with finding the maximum number in this way. you can make it shorter I understood my mistakes and they ware very silly. Thank you Seyyed for helping me ;) Edited by author 30.08.2008 20:34 | WA 2? | kai_99 | 1585. Пингвины | 10 май 2008 18:38 | 1 | WA 2? kai_99 10 май 2008 18:38 | getting WA 1 | Anupam Ghosh,Bengal Engg and Sc Uni,PDSIT,Shibpur,India | 1585. Пингвины | 22 апр 2008 12:59 | 2 | getting WA 1 Anupam Ghosh,Bengal Engg and Sc Uni,PDSIT,Shibpur,India 29 мар 2008 12:14 the problem isnt easy as it seems. can somebody give some hint? or test cases. Believe me the problem is so easy that it appears a bit difficult. Problem does not require any logical, mathematical skills. hint: Do not give attention to the second coming word "Penguin", you should set up counter for Emperor, Macaroni and Little penguins only. Good luck. If you need something you are welcom write to me rustam86@bk.ru | c WA why? | Wang Fei | 1585. Пингвины | 18 дек 2008 14:56 | 4 | #include<stdio.h> void main() { int n,i; int e=0,m=0,l=0,max; char ch; scanf("%d",&n); for(i=0;i<n;i++) { fflush(stdin); ch=getchar(); switch(ch) { case 'E':e++;break; case 'M':m++;break; case 'L':l++; } } max=e;ch='E'; if(m>max){max=m;ch='M';} if(l>max) ch='L'; switch(ch) { case 'E':printf("Emperor Penguin");break; case 'M':printf("Macaroni Penguin");break; case 'L':printf("Little Penguin"); } } Do not use <stdio.h> instead you better to use #include <iostream> using namespace std; good luck I never use iostream. Try to add \n to output. #include<stdio.h> void main() { int n,i,e=0,m=0,l=0,max; char ch[30]; scanf("%d",&n); for(i=0;i<2*n;i++) { scanf("%s",ch); switch(ch[0]) { case 'E':e++;break; case 'M':m++;break; case 'L':l++; } } max=e;ch[0]='E'; if(m>max){max=m;ch[0]='M';} if(l>max) ch[0]='L'; switch(ch[0]) { case 'E':printf("Emperor Penguin");break; case 'M':printf("Macaroni Penguin");break; case 'L':printf("Little Penguin"); } } | Damn, WA#1 | AlMag | 1585. Пингвины | 6 фев 2008 19:53 | 3 | does anyone have it? i won't show my code yet, may be someone passed this problem WA#1? tell, please. Test 1 is usually sample test in the problem description. Check spaces and newlines in your output. Or maybe it is because of difference of compilers. Try to change your input reading part. | Please help to find a mistake | DD | 1585. Пингвины | 8 дек 2007 01:36 | 3 | /* Name:D.cpp Date: Lang:Cpp Environment:MS Visual Studio 2005 Sp1 */ // Defines #define DEBUG 0 #define FILE_INPUT 1 #define FILE_OUTPUT 1 #define FILE_OUTPUT_NAME "D.out" #define FILE_INPUT_NAME "D.in" // Includes #include <cstdio> #include <cmath> #include <cstdlib> #include<string> #include<iostream> // Namespace using namespace std; // SETIO function int setio() { // seting input #if FILE_INPUT // freopen(FILE_INPUT_NAME,"r",stdin); #endif // seting output #if FILE_OUTPUT // freopen(FILE_OUTPUT_NAME,"w",stdout); #endif
// Done,exiting return 0; } // Functions,Procedures,etc // Main function int main() { #ifndef ONLINE_JUDGE setio(); #endif int n,i,a,b,c;string s; a=0;b=0;c=0;s.clear(); cin>>n; for(i=0;i<n;i++) {cin>>s; if (s[0]=='E')a++; else if(s[0]=='M')b++; else if(s[0]=='L')c++; cin>>s; } if (a>b&&a>c) cout<<"Emperor Penguin"<<endl; if (a<b&&b>c) cout<<"Macaroni Penguin"<<endl; else cout<<"Little Penguin"<<endl; //system("pause"); return 0; } #define FILE_OUTPUT_NAME "D.out" #define FILE_INPUT_NAME "D.in" for what is this pice of code??? Edited by author 07.12.2007 14:52 the else statement is related to second if. think about try test 4 E P E P L P M P your program output both Emperor Penguin and Little Penguin | ????????? | Izverg | 1585. Пингвины | 3 фев 2008 05:40 | 4 | Who knows how to solve it? :?) Re: ????????? [SSTtU_#12]snipious_#0 aka Pimenov Sergey Nikolaevich 7 дек 2007 14:50 at first read kormen book, knuth "the art of programming" and after that try to solve it again. |
Страницы: Следующая 3 2 1 |
|