Mel81x Posted March 10, 2012 Report Share Posted March 10, 2012 The Android SDK tutorials are fine but I suppose you have to ask yourself - what do i want to finally accomplish and then go looking for stuff related to what you need to do. Link to comment Share on other sites More sharing options...
Ne0 Posted March 16, 2012 Report Share Posted March 16, 2012 Is it possible to read text from pdf files using C/C++ program ? Want to know the APIs to be used to read the information and store it into a buffer. Link to comment Share on other sites More sharing options...
Somebody Posted April 9, 2013 Report Share Posted April 9, 2013 My current project involves a Monitoring application reading data (via USB) from an embedded device, and then interpreting that data and displaying graphs among other things. I created a Custom Emulator to emulate the functions of the embedded device, such that the Emulator reads data from a CSV file and sends data out through a USB comport. I need the Emulator and the Monitoring application on two separate computers, and preferrably talking via USB. Is there any way I can do this? Scenario: Emulator reads data from CSV and sends data out of a port to which the Monitoring PC is connected via USB. The Monitoring PC receives this data and the Monitoring application will interpret data as if it received it from the embedded device. I tried connecting the two PCs with a USB male-male cable, but the PCs don't detect eachother. Is there anything I'm missing? Like drivers? or switching the send/receive pins/signals? Link to comment Share on other sites More sharing options...
Shantz Posted April 9, 2013 Report Share Posted April 9, 2013 ^^ USB comport? Did you mean emulating serial over USB? If yes, you'd need a serial converter chip (FTDI and vishay are two famous makers) for this in the cable you are using and sending/receiving data would be very simple but limited to the max baud rate of the serial port. Direct USB communication is a big beast. It won't work directly by just connecting two PCs together. You'd need one PC to act as a host and the other as a device. You also need to decide which kind of device will you emulate etc. You can search for a program that allows to act as a filer device or something or may need to write your own drivers (USB drivers are also PITA btw, there are several layers that you need to take care of). Network connection would be the easiest and would not require any special peripherals. You can just use basic socket programming (read first few chapters of stevens) to connect and send/receive data. For displaying graphs, you could either search for tons of graphing libraries available for all languages or use graphviz. I use graphviz for all my graphing/plotting needs. It has a very simple interface and you can also generate .dot files (text files in special graphviz format) which it can read at runtime to create the graphs Link to comment Share on other sites More sharing options...
Somebody Posted April 9, 2013 Report Share Posted April 9, 2013 ^^ USB comport? Did you mean emulating serial over USB? If yes, you'd need a serial converter chip (FTDI and vishay are two famous makers) for this in the cable you are using and sending/receiving data would be very simple but limited to the max baud rate of the serial port. Direct USB communication is a big beast. It won't work directly by just connecting two PCs together. You'd need one PC to act as a host and the other as a device. You also need to decide which kind of device will you emulate etc. You can search for a program that allows to act as a filer device or something or may need to write your own drivers (USB drivers are also PITA btw, there are several layers that you need to take care of). Network connection would be the easiest and would not require any special peripherals. You can just use basic socket programming (read first few chapters of stevens) to connect and send/receive data. For displaying graphs, you could either search for tons of graphing libraries available for all languages or use graphviz. I use graphviz for all my graphing/plotting needs. It has a very simple interface and you can also generate .dot files (text files in special graphviz format) which it can read at runtime to create the graphs Hmm... I already have the two applications that I need. Forget about what I told you about the emulation part before. I'll try again I have an application A that sends data out through USB, and an application B that receives and interprets data that it receives from a USB. In both applications, I just display the available comports, and let the user select the port from which to send/receive data. The thing is, I need to have these applications on two different computers and talking to each other, as in, the application B has to receive data sent out from application A. I thought the best way to do it might be just to use a USB male-male cable, but it looks like it's not as easy as that. How do I configure one PC to be the host and the other to be a client? If this doesn't work, yeah, I could try doing a network connection. I'll lookup how to do some basic socket programming meanwhile. Link to comment Share on other sites More sharing options...
Ne0 Posted April 10, 2013 Report Share Posted April 10, 2013 ^^ +1 to what shantz said .... socket communication is like 10x simpler if you just want 2 programs (in 2 diff computers) to talk to each other .... you can refer to this online tutorial if are new to socket / network programming and want to get started right away ! Link to comment Share on other sites More sharing options...
Somebody Posted May 19, 2014 Report Share Posted May 19, 2014 I went with what Shantz said and got a Null modem cable from FTDI, and that worked perfectly well for the communication. Thanks guys. I have a pretty basic (probably silly) doubt about Linked Lists. When you want to check if a singly linked list is cyclic, all the suggestions are about using two pointers, with one moving two nodes at a time and the other one moving one node at a time. If there's a cycle, the one that goes two steps will meet the slower one eventually. My doubt is, why not just have two nodes with one just sitting at the starting point, and the other one moving one node at a time forward till it goes around to meet the stationary one? Is there anything wrong with doing this? Link to comment Share on other sites More sharing options...
somu Posted May 20, 2014 Report Share Posted May 20, 2014 It won't always be the case that the starting node is part of the cycle in the linked list. Link to comment Share on other sites More sharing options...
AngerSmash Posted May 20, 2014 Report Share Posted May 20, 2014 Anyone here on TopCoder? Link to comment Share on other sites More sharing options...
Somebody Posted May 20, 2014 Report Share Posted May 20, 2014 ^^ I'm not It won't always be the case that the starting node is part of the cycle in the linked list. What do you mean by that? Isn't a circular linked list just a linear linked list with the last node's Next pointing to the first node? Do you mean the case where the last node points to a node in the middle of the list? That would be a weird 'circular' linked list Thank you Link to comment Share on other sites More sharing options...
Ne0 Posted May 21, 2014 Report Share Posted May 21, 2014 ^^ circular ll is more of a problem in the context that you mentioned. It was not the intent. In an otherwise linear list, it happens at times.... mainly due to wrong usage of pointers. And when it happens it can happen anywhere. I've seen cases where the node was pointing to itself causing infinite loops.... Your ex works only when the loop is at the first node, what if the loop is in the mid ? Sent from my Nexus 5 using Tapatalk Link to comment Share on other sites More sharing options...
varundbest Posted June 12, 2014 Report Share Posted June 12, 2014 Cannot seam to understand this thing - Geeko is in worry now because exam is coming up and he has to know what rank he can get in exams. So he go back into the school records and finds the amazing pattern.[/size]He finds that if a student is having a current rank n than his rank in the final exam will be the count positive numbers between in the range [1,n] which are relatively prime to nAs being geek he became curious now he want to calculate the rank of all his classmates in final exam, but he finds this task a bit hard , So he ask you programmers to solve this task for him.Input:The first line of each test file contains a integer t denoting the number of test case.Each test case contains a numbers n representing the current rank of each studentOutput:for each test case output single integer the rank of student in final exam in new line.Constraints:1<= t <= 20001<= n <10^6 Sample Input (Plaintext Link)254Sample Output (Plaintext Link)42My code - #include <iostream> using namespace std; int main() { int t,p=0,a=0; cin>>t; for(int j=1;j<=t;j++) { p=0; for(int i=1;i<=j;i++) { if((t%i==0)&&(j%i==0)) { p++; } } if(p==1) a++; } cout<<a; return 0; } Firstly their sample output is weird, its 5 =4 and 4 = 2 but what about 2 = ??Their solution - #include<stdio.h> #define ll int int scan() { int t=0; char c; c=getchar_unlocked(); while(c<'0' || c>'9') c=getchar_unlocked(); while(c>='0' && c<='9') { t=(t<<3)+(t<<1)+c-'0'; c=getchar_unlocked(); } return t; } ll phi(ll n) { ll result = n; ll i; for(i=2;i*i <= n;i++) { if (n % i == 0) result -= result / i; //printf("%lld\n",result); while (n % i == 0) n /= i; } if (n > 1) result -= result / n; return result; } int main() { int t;ll num; t=scan(); while(t--) { num=scan(); printf("%d\n",phi(num)); } return 0; } Link to comment Share on other sites More sharing options...
KyoyaHibari Posted June 12, 2014 Report Share Posted June 12, 2014 Your code is correct if the input asked for is only the rank of student. But you needs to give 2 types of input. Inputs should be like this 1. t= no. of input ranks you wanna give 2. n1= rank of student 1 3. n2= rank of student 2 . . t+1. nt= rank of student t Output will be 1. new rank of student 1 . . . t. new rank of student t Input 2- wanna give 2 students rank 5- 1st student's rank 4- 2nd " Output 4 2 hope that helps Link to comment Share on other sites More sharing options...
varundbest Posted June 12, 2014 Report Share Posted June 12, 2014 Your code is correct if the input asked for is only the rank of student. But you needs to give 2 types of input. Inputs should be like this 1. t= no. of input ranks you wanna give 2. n1= rank of student 1 3. n2= rank of student 2 . . t+1. nt= rank of student t Output will be 1. new rank of student 1 . . . t. new rank of student t Input 2- wanna give 2 students rank 5- 1st student's rank 4- 2nd " Output 4 2 hope that helps Wrote a code - #include <iostream> using namespace std; void test(int t) { int p=0,a=0; for(int j=1;j<=t;j++) { p=0; for(int i=1;i<=j;i++) { if((t%i==0)&&(j%i==0)) { p++; } } if(p==1) a++; } cout<<a<<endl; } int main() { int n,x,t; cin>>n; x=n; while(x!=0) { cin>>t; test(t); x--; } return 0; } and on my test run, it took 0.1005 seconds to run (on their site's compiler) and 64kb memory but when i submitted it to them, those faggots are like 8+ seconds runtime and 240+ kb memory.... faggots... Link to comment Share on other sites More sharing options...
KyoyaHibari Posted June 12, 2014 Report Share Posted June 12, 2014 Yeah thats looks like correct code. You also need to take into account that n and t values constraints. With int you won't be able to run code for n=10^5 and above. Maybe their compiler must be diff from the one u used. Not able to understand there code Link to comment Share on other sites More sharing options...
varundbest Posted June 12, 2014 Report Share Posted June 12, 2014 Me too lol! And i didn't use my compiler, both are results from their own site. Link to comment Share on other sites More sharing options...
AngerSmash Posted June 12, 2014 Report Share Posted June 12, 2014 Is it codechef? I mostly use python and it always exceeds the time limit. Topcoder FTW. Link to comment Share on other sites More sharing options...
MoonStruckHorrors Posted June 12, 2014 Report Share Posted June 12, 2014 It's HackerEarth. I've solved problems there in the past, works fine most of the times. Link to comment Share on other sites More sharing options...
MoonStruckHorrors Posted June 12, 2014 Report Share Posted June 12, 2014 This is my solution for the problem. The compiler finds it incorrect & times out. Working correctly for the sample input & few custom inputs I've tried. Strange. import java.util.Scanner; import java.util.ArrayList; class ExamTime { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = Integer.parseInt(sc.nextLine()); for(int i=0; i<n; i++) { int count = 0; int cr = Integer.parseInt(sc.nextLine()); for(int j=1; j<cr; j++) { if(EuclidGCD(cr, j) == 1) { count++; } } System.out.println(count); } //System.out.println(EuclidGCD(5, 3)); } public static int EuclidGCD(int a, int { int temp; while(b != 0) { temp = b; b = a % b; a = temp; } return a; } } Used Euclid's GCD Algorithm to find if numbers are relatively prime or not. (Prime if GCD(a, == 1) Link to comment Share on other sites More sharing options...
varundbest Posted June 12, 2014 Report Share Posted June 12, 2014 ^^ IDK but its using hell lotta memory acc. to them... Strange... Btw thanks for the effort Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.