Общий форумI try to parse digits by symbols this way: using System; using System.Text.RegularExpressions; using System.Globalization; using System.Collections.Generic; //Version 2 namespace CSharpV1 { class Program { //static readonly char[] splitChars = { ' ', '\t', '\n', '\r' }; //Version 1 static void Main(string[] args) { var nfi = NumberFormatInfo.InvariantInfo; //Version 4. Symbolic input int curCharDigit; char curChar; var curDigitString = String.Empty; var rootsStack = new Stack<double>(); while ((curCharDigit = Console.Read()) != -1) { curChar = Convert.ToChar(curCharDigit); if (char.IsDigit(curChar) || curChar == '.' || curChar == ',') { curDigitString += curChar; } else { if (curDigitString.Length != 0) { var curDigit = Convert.ToDouble(curDigitString, nfi); var root = Math.Sqrt(curDigit); rootsStack.Push(root); curDigitString = String.Empty; } } } while (rootsStack.Count != 0) { var curRootString = string.Format(nfi, "{0:F4}", rootsStack.Pop()); Console.WriteLine(curRootString); } rootsStack = null; } } } And I get Wrong answer while test 3... The code works fine with example input data. The digits are Integer. What's wrong? I've got it. I didn't parse the last number when the last symbol is digit. Corrected code: using System; using System.Globalization; using System.Collections.Generic; namespace CSharpV1 { class Program { static readonly NumberFormatInfo nfi = NumberFormatInfo.InvariantInfo; static void Main(string[] args) { //Version 4. Symbolic input int curCharDigit; char curChar; var curDigitString = String.Empty; var rootsStack = new Stack<double>(); while ((curCharDigit = Console.Read()) != -1) { curChar = Convert.ToChar(curCharDigit); if (char.IsDigit(curChar)) { curDigitString += curChar; } else { ParseAndAdd(ref curDigitString, rootsStack); } } ParseAndAdd(ref curDigitString, rootsStack); while (rootsStack.Count != 0) { var curRootString = string.Format(nfi, "{0:F4}", rootsStack.Pop()); Console.WriteLine(curRootString); } rootsStack = null; } static void ParseAndAdd(ref string curDigitString, Stack<double> rootsStack) { if (curDigitString.Length != 0) { var curDigit = Convert.ToDouble(curDigitString, nfi); var root = Math.Sqrt(curDigit); rootsStack.Push(root); curDigitString = String.Empty; } } } } Edited by author 14.10.2012 03:14 I uploaded the following solution but it only says "crash": using System; namespace Week2 { class Program { static void Main(string[] args) { int a, b; a = int.Parse(Console.ReadLine()); b = int.Parse(Console.ReadLine()); Console.WriteLine(a + b); } } } It happens because of you use ReadLine. These digits are on the same line, so you should just split them by space. You can find an example there: http://acm.timus.ru/help.aspx?topic=csharp using System; public class Sum { private static void Main() { string[] tokens = Console.ReadLine().Split(' '); Console.WriteLine(int.Parse(tokens[0]) + int.Parse(tokens[1])); } } Edited by author 14.10.2012 01:59Pascal var a,b:real; begin readln(a); readln(b); writeln(a+b); end. Edited by author 10.10.2012 17:42 Edited by author 13.10.2012 20:39 I'm not a Pascal programmer... But... Maybe because these digits are on the same line and you should use "read" instead of "readln"...? Yes, read instead of readln, and also longint instead of real #include <iostream> using namespace std; int main() { int a, c, b, year; double a1, b1, c1; cin >> a >> b >> c; a1=static_cast <double>(a); if(a1<=1024*1024*1024*2-1 && b<=1024*1024*1024*2-1 && c>=1 && c<=100 && a>0 && b>0) { for(year=1; a1=a1*(100-c)/100; year++) { if (a1<=b) { cout << year; break; } } } cin.get(); cin.get(); return 0; }
Please some body tell me why i am gettig wrong answer in this. My code is: #include <iostream> #include <cstdio> #include <vector> #include <cmath> #include <algorithm> #include <string> #include <cstring> #include <string.h> #include <cstdlib> #include <sstream> #include <stack> #include <queue> #include <numeric> #include <utility> #include <cctype> #include <list> #include <climits> #include <signal.h> #include <ctime> #include <map> #include <set> using namespace std; #define ll long long int ll i, j, k, ct=0, m, n, t, x, y, z, tc, a[200000],s; vector<ll> ans; int main(){ cin >> n >> s; for(i = 0; i < n; i++){ cin >> a[i]; } sort(a,a+n); for ( i = n-1; i > 0 ; i-- ) { if ( a[i] + a[i-1] <= s ) { break; } } // cout << x << " " << y << endl; if(s%2==0){ x = i+1; y = i; //z = n-1; while ( x < n && y >= 0 ) { ans.push_back( a[y] ); ans.push_back( a[x] ); x++; y--; } while ( x < n ) { ans.push_back( a[x] ); x++; } while ( y >= 0 ) { ans.push_back( a[y] ); y--; } } else { y = i; while ( i < n && a[i] == a[y]){ ans.push_back( a[i] ); i++; } y--; x = i; while ( x < n && y >= 0 ) { ans.push_back( a[x] ); ans.push_back( a[y] ); x++; y--; } while ( x < n ) { ans.push_back( a[x] ); x++; } while ( y >= 0 ) { ans.push_back( a[y] ); y--; } } ct = 0; for ( i = 0; i < ans.size(); ) { if( i == ans.size() - 1){ ct++; i++; } else{ if( ans[i] + ans[i+1] <= s){ ct++; i+=2; } else{ ct++; i++; } } } cout << ct << endl; for ( i = 0; i < ans.size(); i++) { cout << ans[i] << " "; } return 0; } Edited by author 13.10.2012 20:42 My god! When I use gcc I get the right anwer, but vc++2010 doesn't. What should I do? There is still time left in the competition...? I have a problem with test 2 too Edited by author 14.10.2012 00:59 сам ни до конца понял я условие понял, но ва6. Edited by author 14.10.2012 00:59 числа из отрезка подходят под нормальный сигнал! Edited by author 14.10.2012 00:59 I solved this problem on Pascal and was AC. But i wrote same program on C and C++. It gives same answers on same tests on my machine but gives WA on test 1 when i submit. These my programs: On pascal:: var a:array[1..10000] of integer; k,n,m,i:integer; s:longint; procedure cle; var i:integer; begin for i:=1 to n do a[i]:=0; end; begin read(n,m); cle; s:=0; for i:=1 to m do begin readln(k); if k<>0 then inc(a[k]); end; for i:=1 to n do begin if a[i]<>0 then writeln(a[i]/m*100:2:2,'%') else writeln('0.00%'); end; end. On C: #include <stdio.h> void main(){ int k,n,m,i; int a[10000]; scanf("%d %d\n",&n,&m); for (i=1;i<=n;i++) a[i]=0; for (i=1;i<=m;++i){ scanf("%d",&k); if (k!=0) a[k]++; } for (i=1;i<=n;++i){ if (a[i]!=0) printf("%2.2f%\n",(float)a[i]/m*100); else printf("0.00\n"); } } 1) Use "double" instead of "float". 2) Don't use Pascal, 'cause C++ is really cool language. P.S. I don't understand how can people write theese "begin ... end" so many times? I don't understand people who think they are cool enough to speak such foolish things ;) Pascal is not worse than C++, and it is up to one to choose what language to use - as for me I use Pascal and I am in Top 10 :) Safe Bird uses C++ - but he does not scream that C++ is better... P.S. Sorry, can not control myself when Pascal in under attack ;) RESPECT++++++ PASCAL RULEZZZ!!!! Hmm... Pascal is not spported at World Finals now. Best programmers have started using Java. Maybe Timus must do the same - substitute Pascal to Java. Don't you want to double all timelimits for "fast" Java programs to pass them? :))) oooh. Yesss. Java is good. I will glad if timus add Java compiler to this contest "Pascal is not spported at World Finals now" - с этого года что ли? Pascal provided but not supported read this: http://icpc.baylor.edu/systems/finals/pascal.htm Pascal will not be removed from Timus of course. Java will be added as soon as possible, but not to February, 11. It is possible to recalculate all timelimits for Java. But it is impossible to make all problems solvable in Java. Edited by author 04.02.2006 15:05ACM.Tolstobrov_Anatoliy[Ivanovo SPU] :) [1] // Задача 1263. Выборы 4 фев 2006 18:58 deleted Edited by author 26.10.2018 14:38 deleted Edited by author 26.10.2018 14:37 Vedernikoff Sergey (HSE: EconomicsForever!) Re: +++ [1] // Задача 1263. Выборы 16 фев 2009 03:38 And why it is problem to solve it in Java? What we need for solution - just one array int[1000] But I really don't understand why timelimit is so small - memory is not crucial part of this problem at all... memory is not crucial part of this problem at all... Maybe author wanted to cut off DP way of solving this problem or something like this. I did't say that Pascal is bad, nasty, ugly, damned language or something like it. But... U must agree with me that up to now there is no compiler for Pascal that can be compared with MVC++ or g++. Theese make really good machine code. :) And IMHO this language is uncomfortable to write algorithms and serious projects. What for Top 10... over some year Top 10 or even Top 50 can became consisting only of Pascal (or - that's terrible - Java) users. Even BASIC coders could be cool because they ARE cool. You think we prefer language? Often programming language prefers us. Pascal is popular in Russia just because of traditions begun with 80's. P.S. I accept your apology, but "LOL" is offensive, don't you think? ДИМАН VERY GOOD MAN, НАПИСАЛ LOL, НАПИШИ ЕМУ ТАКЖЕ:) I suggest to make a voting. I use pascal about 5 years for solving problems. And as for me, I think that pascal is not so uncomfortable to write algorithms. Edited by author 07.02.2006 21:39 Hi! I'm first time here and seems the last - cause there is no Java support. Are you going to add it soon? Pascal is the worst language I ever seen..... Shut up! Pascal Will Newer Die! Edited by author 18.10.2006 08:05 In C++ very hard syntax, and Pascal is good language too Currently I'm using C++ for solving problems, but can say: Pascal foreva! C++ has many drawbacks which are worse than just long "begin .. end" I solved problems using all languages available on this server and Java seems to be most convenient for me.. #include <iostream> #include <stdio.h> using namespace std; int main() { int br[10024],i,m; double n,a; float sum; cin>>n>>a; sum=100/a; for(i=1;i<=10024;i++) { br[i]=0; } for(i=1;i<=a;i++) { cin>>m; br[m]++; } for(i=1;i<=n;i++) {
printf("%.2lf",(br[i]*sum)); cout<<"%"<<endl; } return 0; } 1) Look how your C++ program will work with n=10000;) 2) You've forgotten about percent sign in else printf("0.00\n"); 3) Don't use % in printf, use %% (it will show as %) 4) LEARN C++ well before writing on it! Edited by author 03.02.2006 17:57 >> 2) You've forgotten about percent sign in else printf("0.00\n"); Is it really necessary? Can anyone translate my solution below into C++? I want to learn programming in C/C++ too :) type TArray=array of dword; var arr:TArray; m,n,c,i:dword; begin readln(n,m); setlength(arr,n+1); for i:=1 to n do arr[i]:=0; for i:=1 to m do begin readln(c); arr[c]+=1; end; for i:=1 to n do begin writeln((arr[i]*100/m):2:2,'%'); end; end. if input is sample input,can output be : 2 3 6? And why?thx Yup, output is correct, because 3 is a friend with 1, 2, 4, 5 and 6 is a friend with 7. So each member of each team has at least one friend in the opposite team Yup, output is correct, because 3 is a friend with 1, 2, 4, 5 and 6 is a friend with 7. So each member of each team has at least one friend in the opposite team wtf? why 6 and 7 are friends? this problem don't only a result!!! How can we make this results -- 0.001 sec -- 1 128 KB ? This is the best result for this problem. I wonder how can we get this results. You can see this result by clicking the link Solution Rating on problem statement. :: http://acm.timus.ru/rating.aspx?space=1&num=1290 :: Edited by author 08.10.2012 12:45 Edited by author 08.10.2012 12:46It is not possible to achieve 0.001 sec result with the current judge. The measurement for an empty program that only calls puts("\n"); is 0.015 at this time. Until the measurement mechanism is changed, those who submitted results years ago will be the only ones to achieve 0.001. Give 9 test please. Edited by author 12.10.2012 14:16 Edited by author 12.10.2012 14:16 My program print this result: 9 212122112 1.Pay attention 0 < ai < bi < 1e9. (I forgot the 0 and 1e9 axis...then wa teat 2 for many time) 2.The data of test 3 maybe 1 1 1000000000 b answer: 0 1 I make an error while recursion to the leaf note. I return the l index instead of the axis it map to. T T Edited by author 11.10.2012 19:04 Angles must be strogly acute? I.e., right angles (pi/2) are restricted? See first sample. It is now absent, but before the sample was corrected there was right angle... My AC solution rejects right angles I got AC when I deleted right angles. I had WA before that. It seems timing has changed since the earlier years on the server. When the following program gets WA in 0.015, you know 0.001 is not possible any more: #include <stdio.h> int main() { puts( "0" ); } Too bad that those of us solving problems now don't get time rated on the same scale as those who came before. But if your code work 0.5 now, in 2003 he worked more than 1 sec The fact that computers are faster today is not the point. In fact, it makes the 0.015 vs. 0.001 difference even more crazy -- computers today are *not* 15 times slower than in 2003! Obviously it is a difference in time measurement technique or a system difference that causes the measurements to differ. When such a measurement difference occurs, all problems should be re-rated for time, it's impossible to compete for time rating on O(1) problems when the fastest possible measurement today for an empty program is 15 times greater than it used to be. must I roped off all the nails with shortest rope? |
|