Sponsored Content
Top Forums Programming Finding items that occur more than once in a vector Post 302520928 by Loic Domaigne on Monday 9th of May 2011 04:38:20 PM
Old 05-09-2011
If you can, store the vertices list using a map<int,int>. The key would be the vertex (that may have duplicate), and the data would be the number of occurrence. Using this data
structure, you have readily all information that you need:
  • the element without duplicate has only one occurrence
  • otherwise it is an element with duplicate.
Below a snippet for your "inspiration":
Code:
#include <map>
#include <iostream>

typedef std::map<int,int> list_t;
list_t list;

int
main()
{
   int x;
   do {
      std::cin >> x;
      if (x>=0) ++list[x];
   }
   while (x>=0);

   std::cout << "elements without duplicate :";
   for(list_t::iterator it=list.begin(); it!=list.end(); ++it) {
      if (it->second==1) std::cout << it->first << " ";
   }
   std::cout << std::endl;

   std::cout << "elements that have duplicate :";
   for(list_t::iterator it=list.begin(); it!=list.end(); ++it) {
      if (it->second>1) std::cout << it->first << " " ;
   }
   std::cout << std::endl;
}

HTH, Loïc
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Why SIGKILL will occur?

Hi Gurus, I am executing my Datastage jobs on UNIX operating System. While running the jobs i am getting the following error: main_program: Unexpected termination by Unix signal 9(SIGKILL) Can any one please let me know what are the possible situations where this SIGKILL will arrise? ... (9 Replies)
Discussion started by: choppas
9 Replies

2. Shell Programming and Scripting

how many times a word occur in afile

i want a shell script program for how many times a word occur in a file. i need not the line number but i want the counts of the particular word for eg:- hai how r u.. i am from andhra pradesh.. i am from tenali.i need this answer.i need it urgently.. i hope u will answer this ... ... (9 Replies)
Discussion started by: madhu.it
9 Replies

3. Shell Programming and Scripting

awk between items including items

OS=HP-UX ksh The following works, except I want to include the <start> and <end> in the output. awk -F '<start>' 'BEGIN{RS="<end>"; OFS="\n"; ORS=""} {print $2} somefile.log' The following work in bash but not in ksh sed -n '/^<start>/,/^<end>/{/LABEL$/!p}' somefile.log (4 Replies)
Discussion started by: Ikon
4 Replies

4. Shell Programming and Scripting

finding missing items in file

I have a need to compare 2 files, then print results to file. Need to find items from file2 that are not found in file 1. thanks in advance! example: file 1: abcde=12 fffff=6 bbbb=35 file2: abcde=12 fffff=6 bbbb=35 ccccc=10 kkkkk=45 (8 Replies)
Discussion started by: discostu
8 Replies

5. Shell Programming and Scripting

To find number of char occur

To find out number of "|" symbol is available in file: Input: a|b|c|d|z Ouput: 4 I am using below set of commands,It is working... Anybody have anyother solution using sed / awk. cnt=`wc -c <1.txt` cnt1=`tr -d "|" <1.txt >c.dat` cnt2=`wc -c <c.dat` outp=`expr $cnt... (19 Replies)
Discussion started by: Jairaj
19 Replies

6. UNIX for Dummies Questions & Answers

C shell loop problem occur

Hi all, i create 2 file Config path1 5 group1 path2 6 group2 path3 10 group1 path4 15 group2 Confine group1 andrew group2 alan In my C shell script i write like this: set line_array = (`cat $app_dir/config`) set line_array_2 =... (0 Replies)
Discussion started by: proghack
0 Replies

7. Shell Programming and Scripting

Print lines where variables occur more than once using grep

Hello, I want to only print lines where variables occur more than once using grep. For eg: Input: $this is a comment int a,b,c,b; int b,c; int d,e; int f,g,f; x=y+5; For the above input, the output would be int a,b,c,b; int f,g,f; I have done grep... (3 Replies)
Discussion started by: prasanna1157
3 Replies

8. Shell Programming and Scripting

Help with Perl script that can check a URL and notifiy when changes occur

I'm a scripting newbie and I'm trying to learn. No better way than being assigned a project. So basically, I'm trying to come up with a script that can periodically check a URL and then notify when changes occur to the file. So what I'm thinking is that I need to devise a PERL script that... (3 Replies)
Discussion started by: adam1mc
3 Replies

9. Cybersecurity

Where does Ciphering & Encryption occur?

Hello everyone. Upon reading the recent news about the NSA paying RSA to use a faulty cipher suite for it's default, it got me thinking... During a connection say for SSL, what is it that "knows" the rules for ciphers? Are these rules stored on the NIC? can they be edited, changed or appended? ... (3 Replies)
Discussion started by: Lost in Cyberia
3 Replies
protocols.map(4)					     Kernel Interfaces Manual						  protocols.map(4)

NAME
protocols.map - Specifies node names for protocols configured on your machine. SYNOPSIS
/var/adm/sendmail/protocols.map DESCRIPTION
This file contains the Phase IV, Phase V, UUCP, and X25 node names for your system if the respective protocols are running on your machine. The format of the file is as follows: protocols?Phase_IV_name?Phase_V_name?UUCP_name?X25_name. The string between the delimeters (?) is empty if a particular protocol is not running on your machine. If no protocols are running on your machine, the file contains the follow- ing string: protocols???? If you are generating the hostname.m4 configuration file manually, you must update the protocols.map file manually as well. If your system is a member of a TruCluster Server cluster, you must maintain or create the protocols.map file as a Context-Dependent Symbolic Link (CDSL). See the System Administration guide for more information. In addition, your hostname.m4 configuration file is instead named after the cluster alias, i.e., cluster_alias.m4. The following parame- ters in the hostname.m4 file affect the protocols.map file: If you have defined or updated this parameter in your hostname.m4 file, you must specify the UUCP_name parameter in the protocols.map file. Use your system's UUCP host name. If you have defined or updated this parameter in your hostname.m4 file, you must specify the Phase_IV_name parameter in the protocols.map file. Also, if you have defined any nicknames for DECnet PhaseIV node name in the _My Nicknames parameter of your hostname.m4 file, you must add them to the protocols.map file below the protocols entry as follows: phaseiv: nickname If you enter more than one nickname, put a space between each nickname. You also need to add your DECnet PhaseIV node address as follows: phaseivaddr: address If you have defined or updated this parameter in your hostname.m4 file, you must specify the Phase_V_name parameter in the protocols.map file. Also, if you have defined any nicknames for DECnet PhaseV node name in the _My Nicknames parameter of your hostname.m4 file, you need to add them to the protocols.map file below the protocols entry as follows: phasev: nickname If you enter more than one nick- name, put a space between each nickname. If you have defined or updated this parameter in your hostname.m4 file, you must specify the X25_name parameter in the protocols.map file. Use your system's unqualified node name. RELATED INFORMATION
Commands: sendmail(8) Files: sendmail.cf(4), sendmail.m4(8) Network Administration delim off protocols.map(4)
All times are GMT -4. The time now is 03:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy