Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения |
Страница 2 |
Против Угнетения Колдовских Народов-Изгоев(ПУКНИ) ахахахахахахахахах | Egor Sibriaev | 1446. Волшебная шляпа | 9 дек 2021 19:15 | 1 |
|
AC but have a weird problem | fyq123 | 1446. Волшебная шляпа | 19 окт 2019 00:51 | 1 |
I use c++,my code is behind. But there is a weird problem . When i define n as int and use cin>>n,the program can't receive the name have more than two word or have symbols like '-'. So i have to define n as a string and transfer the string into a int,why this strange thing happen? #include<iostream> #include<string.h> #include<cstring> using namespace std; int main() { char room[4][1000][210]; memset(room,0,sizeof(room)); int k=0,nth[4]={0}; char n[10]; cin.getline(n,10,'\n'); int len=10; while(n[len]=='\0'){len--;} int temp=1; for(int i=len;i>=0;i--) { k+=(n[i]-48)*temp; temp*=10; } for(int i=0;i<k;i++) { char temp[210],temp1[20]; cin.getline(temp,210,'\n'); cin.getline(temp1,20,'\n'); if(temp1[0]=='S') { strcpy(room[0][nth[0]],temp); nth[0]++; } else if(temp1[0]=='H') { strcpy(room[1][nth[1]],temp); nth[1]++; } else if(temp1[0]=='G') { strcpy(room[2][nth[2]],temp); nth[2]++; } else { strcpy(room[3][nth[3]],temp); nth[3]++; } } /* omit so this is not a correct solution*/ } |
WA 3 | Frog | 1446. Волшебная шляпа | 14 ноя 2014 14:21 | 2 |
WA 3 Frog 14 ноя 2014 14:11 I use fgets to read from stdin, when I try to store name in an array with length 201, i got WA 3,but when I changed the length to 210, I got AC, who can tell me why? i got it: if the name has exactly 200 symbols, the name and the newline will be read into two strings. |
ATTENTION | [TDUweAI] daminus | 1446. Волшебная шляпа | 27 июн 2013 22:32 | 1 |
ATTENTION [TDUweAI] daminus 27 июн 2013 22:32 If your code on pascal, don't use "CASE x oF" it's got CE(Compilation error) |
WA#4 No idea!! please help!!!!!! | BOyKA | 1446. Волшебная шляпа | 21 окт 2013 14:59 | 3 |
4 Ivan Ivanov Gryffindor Mac Go Nagolo Hufflepuff Um Bridge Slytherin Tatiana Henrihovna Grotter Ravenclaw |
nima xato | Yangiboyev Bekmurod | 1446. Волшебная шляпа | 22 янв 2012 14:48 | 4 |
nima xato Yangiboyev Bekmurod 16 янв 2012 23:57 #include <iostream> #include <string> using namespace std; int main () { string s[2002]; unsigned int n; bool t=false; bool t1=false; bool t2=false; bool t3=false; cin>>n; for( int i=1;i<=2*n;i++) { cin>>s[i]; if("Slytherin"==s[i]) t=true; if("Hufflepuff"==s[i]) t2=true; if("Gryffindor"==s[i]) t1=true; if("Ravenclaw"==s[i]) t1=true; } if(t) { cout<<"Slytherin:"<<endl; for(int i=1;i<=n;i++) if("Slytherin"==s[2*i]) cout<<s[2*i-1]<<endl; cout<<endl; } if(t2) { cout<<"Hufflepuff:"<<endl; for(int i=1;i<=n;i++) { if("Hufflepuff"==s[2*i]) cout<<s[2*i-1]<<endl; } cout<<endl; } if(t1) { cout<<"Gryffindor:"<<endl; for(int i=1;i<=n;i++) if("Gryffindor"==s[2*i]) cout<<s[2*i-1]<<endl; } if(t) { cout<<"Ravenclaw:"<<endl; for(int i=1;i<=n;i++) if("Ravenclaw"==s[2*i]) cout<<s[2*i-1]<<endl; } return 0; } Xatolaringiz juda ko'p, asosiy o'rindagi xato kiritish jarayonidagi xato! ya'ni "cin" operatori probel tashlanganda ham kiritish tugaganini bildiradi, ism esa 1 talik, 2-talik,3-talik... bo'lishi mumkin cin.getline(s[i]) yana qanday xato "cin" tashqari yana nima xato |
test 3 Crash (access violation) | amirani | 1446. Волшебная шляпа | 16 янв 2012 17:39 | 1 |
what can be the reason of Crash (access violation) on test 3.? |
WA1 Really! | VNXtreMe | 1446. Волшебная шляпа | 9 дек 2013 23:52 | 3 |
This is one of the easiest problem in timus and I can't believe i'm getting WA1 for this problem. Im solving this problem using C++ and I'm using getline method from sstream to get the input. I'm storing the names in vectors and printing them with empty lines between the houses. I know Test 1 is usually the given data, but im getting WA1 even though I'm getting the same answer in my computer as given in the problem description. Does anyone know how to overcome this WA1 problem? Edited by author 03.01.2012 15:53 Ok so I found the problem, I know timus is piping the input and output via text files and the problem in that was that repeated getlines will fail. So I used the piping method as mentioned in timus and the problem was visible as it printed empty output to the output file. If you want to know how to pipe inputs and outputs follow the below link(look under Other notes section)- http://acm.timus.ru/help.aspx?topic=cppFor example : cin>>number; while(true){ getline(cin,input1); getline(cin,input2); if(somecondition) break; } However while(getline(cin,input)) {do} will work. But since we need 2 inputs the above code will fail as getline will return empty strings due to the reasons mentioned here- http://www.cplusplus.com/forum/articles/6046/ I overcame the problem using cin.ignore() just before entering the loop as to flush the input stream correctly and the corrected code of above may look like the code below- cin>>number; cin.ignore();//flushes input stream while(true){ getline(cin,input1); getline(cin,input2); if(somecondition) break; } If this didn't work then I suggest you to program in other languages. Edited by author 04.01.2012 10:41Thanks... great help indeed ... :) |
I have AC without writing spaces between faculties! | Alex.pas | 1446. Волшебная шляпа | 14 дек 2011 00:07 | 2 |
Is it mistake in example or bug?(I write on pascal) Edited by author 13.12.2011 23:41 Your output is the same as in the sample test. :) |
Oh my GOD, C# is very good at string | DR. Zhihua Lai | 1446. Волшебная шляпа | 13 дек 2011 17:57 | 1 |
usually i don't code in C# but I just found that C# is very good at this kind of problems... string manipulation is great in C#... you have many handy things such as List, Dictionary etc.. |
what is wrong? Pascal | Kirill Pugachev | 1446. Волшебная шляпа | 28 окт 2012 18:07 | 2 |
var n,i,j,k:integer; s,h,g,r:string; a:array[1..200] of string; begin s:='Slytherin'; h:='Hufflepuff'; g:='Gryffindor'; r:='Ravenclaw'; readln(n); for i:=1 to 2*n do readln(a[i]); writeln(s,':'); for i:=2 to 2*n do if a[i]=s then writeln(a[i-1]); writeln; writeln(h,':'); for i:=2 to 2*n do if a[i]=h then writeln(a[i-1]); writeln; writeln(g,':'); for i:=2 to 2*n do if a[i]=g then writeln(a[i-1]); writeln; writeln(r,':'); for i:=2 to 2*n do if a[i]=r then writeln(a[i-1]); end. a:array[1..2000] of string; |
If you have WA1 on C++ | _-Re@l-_ | 1446. Волшебная шляпа | 4 ноя 2011 23:23 | 1 |
If you have WA1 on C++, it means that you are doing input not right. In that case I recommend you to decide this problem on Pascal - I haven't problems with input such I have in C++. |
Страница 1 |
WA1. What's wrong with the output? (Solved!) | Radiosterne | 1446. Волшебная шляпа | 26 окт 2011 19:57 | 2 |
The wrong line was: cout << endl << "Griffyndor:" << endl; Edited by author 26.10.2011 03:43 Edited by author 26.10.2011 19:58 Edited by author 26.10.2011 19:58 Solved! While solving this problem, pay attention to spelling of faculties ;-) |
WA #1 C++ | Panzer | 1446. Волшебная шляпа | 12 дек 2010 01:00 | 1 |
Why I have WA? On my computer everything is ok... Please Help. Code: #include <cstdlib> #include <iostream> #include <string> using namespace std; int main(int argc, char *argv[]) { int n;
scanf("%d", &n);
string *tab = new string [n*2];
//-------------------INPUT------------------------
for(int i=0; i<n*2; i++){ getline(cin, tab[i]); }
string *list = new string [n+7];
//------------------Slytherin----------------------- int pos=0; //pos - position list[pos]="Slytherin:";
for(int i=0; i<n*2; i+=2){ if(tab[i+1][0]=='S'){ pos++; list[pos]=tab[i]; } } pos++; //------------------Hufflepuff----------------------- pos++; list[pos]="Hufflepuff:";
for(int i=0; i<n*2; i+=2){ if(tab[i+1][0]=='H'){ pos++; list[pos]=tab[i]; } } pos++; //------------------Gryffindor----------------------- pos++; list[pos]="Gryffindor:";
for(int i=0; i<n*2; i+=2){ if(tab[i+1][0]=='G'){ pos++; list[pos]=tab[i]; } } pos++; //------------------Ravenclaw----------------------- pos++; list[pos]="Ravenclaw:";
for(int i=0; i<n*2; i+=2){ if(tab[i+1][0]=='R'){ pos++; list[pos]=tab[i]; } }
//-------------------OUTPUT---------------------------
for(int i=0; i<n+7; i++){ cout << list[i] << endl; }
delete [] tab; delete [] list;
system("pause"); return EXIT_SUCCESS; } |
Something with getline() function . Please let me know... | Yermakov Alex <ONPU> | 1446. Волшебная шляпа | 10 янв 2017 21:30 | 3 |
#include <iostream> #include <string.h> int main() { char grif[1001][202],sliz[1001][202],huff[1001][202],rave[1001][202],name[202],group[20]; int n,i,gcur=0,scur=0,hcur=0,rcur=0; std:: cin >> n; while( n>=0 ) { std:: cin.getline(name,202); std:: cin.getline(group,20);
if(!strcmp(group,"Slytherin")) { strcpy(sliz[scur],name); scur++; } if(!strcmp(group,"Hufflepuff")) { strcpy(huff[hcur],name); hcur++; } if(!strcmp(group,"Gryffindor")) { strcpy(grif[gcur],name); gcur++; } if(!strcmp(group,"Ravenclaw")) { strcpy(rave[rcur],name); rcur++; }
--n; }
std::cout<<"Slytherin:\n"; for( i=0; i<scur; ++i ) std:: cout << sliz[i] << '\n'; std::cout<<'\n';
std::cout<<"Hufflepuff:\n"; for( i=0; i<hcur; ++i ) std:: cout << huff[i] << '\n'; std::cout<<'\n';
std::cout<<"Gryffindor:\n"; for( i=0; i<gcur; ++i ) std:: cout << grif[i] << '\n'; std::cout<<'\n';
std::cout<<"Ravenclaw:\n"; for( i=0; i<rcur; ++i ) std:: cout << rave[i] << '\n'; std::cout<<'\n';
return 0; } This is madness! Don't write such code =) int main() { int students; cin >> students; map< string, vector<string> > house_to_students; for (int student = 0; student < students; student++) { cin.ignore();
string student_name; getline(cin, student_name); string house; cin >> house; house_to_students[house].push_back(student_name); } for (auto house : { "Slytherin", "Hufflepuff", "Gryffindor", "Ravenclaw" }) { cout << house << ":" << endl;
for (auto student : house_to_students[house]) cout << student << endl; cout << endl; } } It happened bcs of cin function In the input they give n and endl after n; so, somehow getline reads this endl as a string, so you can do this insted of "cin>>n" use "scanf("%d\n", &n); |
WA#3 help please! | Smusenok Sergiy Andriyovich (KhAI) | 1446. Волшебная шляпа | 18 авг 2009 19:32 | 2 |
who knew, what is test #3? Oh,i find my mistake! now AC(#2716357 0.031 377 Kb). the last symbol must be '\n'!!! and you must use DP and you haven't MLE! (sorry for my english) |
WA #1 no idea what is wrong... | Piotr | 1446. Волшебная шляпа | 19 июн 2009 23:10 | 1 |
In my opinion everything is ok but i have WA#1 #include <stdio.h> #include <string.h> #include <stdlib.h> int main() { int n; int liczba, y=0, i=0, z; int lengthG = 0, lengthS = 0, lengthR = 0, lengthH = 0;
char g[250000]; char s[250000]; char h[250000]; char r[250000]; char wyraz[2500]; char szkola[2500];
scanf("%d", &n);
for(i=0; i<n; i++) { fflush(stdin); gets(wyraz); scanf("%2000s", szkola);
liczba = strlen(wyraz);
if(strcmp( szkola , "Gryffindor" ) == 0 ) { z=0; for(y=lengthG; y<(liczba + lengthG); y++) { g[y] = wyraz[z]; z++; }
g[lengthG+liczba] = '\n'; lengthG += liczba + 1; }
if(strcmp( szkola , "Slytherin" ) == 0) { z=0; for(y=lengthS; y<(liczba + lengthS); y++) { s[y] = wyraz[z]; z++; }
s[lengthS+liczba] = '\n'; lengthS += liczba + 1; }
if(strcmp(szkola, "Hufflepuff") == 0) { z=0; for(y=lengthH; y<(liczba+lengthH); y++) { h[y] = wyraz[z]; z++; }
h[lengthH+liczba] = '\n'; lengthH += liczba + 1; } if(strcmp(szkola, "Ravenclaw") == 0) { z=0; for(y=lengthR; y<(liczba+lengthR); y++) { r[y] = wyraz[z]; z++; }
r[lengthR+liczba] = '\n'; lengthR += liczba + 1; } }
g[lengthG] = '\0'; r[lengthR-1] = '\0'; s[lengthS] = '\0'; h[lengthH] = '\0';
printf("Slytherin:\n"); puts(s);
printf("Hufflepuff:\n"); puts(h);
printf("Gryffindor:\n"); puts(g);
printf("Ravenclaw:\n"); puts(r); } |
Who can tell me what is the test 3??? | Tural Gulmammadov | 1446. Волшебная шляпа | 9 янв 2018 20:19 | 2 |
|
This is my code with !!!Crash!!! | Mihr Hovsep | 1446. Волшебная шляпа | 6 апр 2009 02:56 | 2 |
# include <iostream.h> # include <string.h> int main () { char a[2002][202]; char b[10000][1000]; char c[10000][1000]; char d[10000][1000]; char e[10000][1000]; int n,i,j=0,k=0,m=0,h=0; cin>>n; for (i=0;i<2*n;i++) cin.getline (a[i],2002,'\n'); for (i=0;i<2*n;i=i+2) { if (a[i+1][0]-'0'=='S'-'0') { strcpy(b[j],a[i]); j++; } else if (a[i+1][0]-'0'=='H'-'0') { strcpy(c[k],a[i]); k++; } else if (a[i+1][0]-'0'=='G'-'0') { strcpy(d[m],a[i]); m++; } else if (a[i+1][0]-'0'=='R'-'0') { strcpy(e[h],a[i]); h++; } } cout<<"Slytherin:"<<endl;; for (i=1;i<=j;i++) cout<<b[i]<<endl; cout<<'\n'<<"Hufflepuff:"<<endl; for (i=1;i<=k;i++) cout<<c[i]<<endl; cout<<'\n'<<"Gryffindor:"<<endl; for (i=1;i<=m;i++) cout<<d[i]<<endl; cout<<'\n'<<"Ravenclaw:"<<endl; for (i=1;i<=h;i++) cout<<e[i]<<endl; return 0; } Tell mi what to do,please, and sorry for my English. your sorce is wronge it is crashing because of char a[2002][202]; char b[10000][1000]; char c[10000][1000]; char d[10000][1000]; char e[10000][1000]; you got to change to: char a[103][1002]; char b[102][1002]; char c[102][1002]; char d[102][1002]; char e[102][1002]; but on the first test the program output : Hufflepuff: Gryffindor: Ravenclaw: the wright answer is : Slytherin: Zlobeus Zlei Um Bridge Hufflepuff: Mac Go Nagolo Gryffindor: Ivan Ivanov Garry Potnyj Herr Mionag-Ranger Ravenclaw: Tatiana Henrihovna Grotter |
Why Compile Error | Hayk Blrtsyan | 1446. Волшебная шляпа | 27 авг 2007 14:19 | 3 |
Here is my solution in C++ I delete my solution becouse I resive ansver . Edited by author 27.08.2007 14:22 Edited by author 27.08.2007 14:22 Look at attentively =) >> printf("%s\n", l[3][i]); printf("\n");s (symbol 's' in the end of string) |