Sponsored Content
Top Forums Programming Words combinations without repetition Post 302501869 by homeboy on Saturday 5th of March 2011 08:56:37 AM
Old 03-05-2011
Actually,I think "AB" and "BA" should be treat as two different conditions.If so,my code shows how to do this(produce 2 words from 3 words).While if not,before doing the count(),you can sort the oss.str() to make sure there is only "AB" or "BA" in the set.
Code:
#include <iostream>
#include <sstream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <list>
#include <set>

using namespace std;


int main()
{
	string ch[] = {"THIS","IS","OK"};
	vector<string> vec(ch,ch+3);
	set<string> st;

	sort(vec.begin(),vec.end());

	do{
		ostringstream oss;
		vector<string>::iterator pos = vec.begin();	
		oss<<*pos<<*(pos+1);
		if(!st.count(oss.str()))
			st.insert(oss.str());
	}while(next_permutation(vec.begin(),vec.end()));
	
	copy(st.begin(),st.end(),ostream_iterator<string>(cout,"\n"));
}


Last edited by homeboy; 03-05-2011 at 11:44 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Random numbers without repetition

Is anyone know some scripts to generate random number without repetition using bash; for example generate 10 different random numbers. Thanks (8 Replies)
Discussion started by: asal_email
8 Replies

2. UNIX for Advanced & Expert Users

Looping/Repetition in Batch files

Hi All, I'm just new to UNIX, does anyone know how to create a batch file in UNIX that does the following routines: 1.) process multiple files in a directory in DOS, I set my sample input file as: set INPUTFILE=%1 in UNIX>> ???? 2.) every file to be processed by executing a program... (1 Reply)
Discussion started by: kimpot7268
1 Replies

3. Shell Programming and Scripting

Looping/Repetition in Batch files

Hi All, I'm just new to UNIX, does anyone know how to create a batch file in UNIX that does the following routines: 1.) process multiple files in a directory in DOS, I set my sample input file as: set INPUTFILE=%1 in UNIX>> ???? 2.) every file to be processed by executing a program... (2 Replies)
Discussion started by: kimpot7268
2 Replies

4. Shell Programming and Scripting

How to check the repetition values in a file using bourne shell

Hi all, I have a scenario, like consider a file abc.txt, inside abc.txt, the contents is value1 = aaa, value2 = bbb, value3 = ccc, value1 = ddd. In this situation i need to throw an error for the repeatation of keys like "value1" is repeating twice. how to handle this using bourne... (1 Reply)
Discussion started by: Nandagopal
1 Replies

5. Shell Programming and Scripting

Count the repetition of a Field in File

Hi, Thanks for keeping such a help-full platform active and live always. I am new to this forum and to unix also. Want to know how to count the repetition of a field in a file. Anything of awk, sed, perl, shell script, solution are welcomed. Input File------------------ abc,12345 pqr,51223... (10 Replies)
Discussion started by: indian.ace
10 Replies

6. UNIX for Dummies Questions & Answers

Syntax Help | unix | grep | regular expression | repetition

Hello, This is my first post so, Hello World! Anyways, I'm learning how to use unix and its quickly become apparent that a strong foundation in regular expressions will make things easier. I'm not sure if my syntax is messing things up or my logic is messing things up. ps -e | grep... (4 Replies)
Discussion started by: MykC
4 Replies

7. UNIX for Advanced & Expert Users

Counting the number of repetition of a pattern

the o/p of a command is -bash-2.05b# grep -o a * cc:a dd:a a dd:a office:a a a a a a a a a a a a a a (2 Replies)
Discussion started by: an2up
2 Replies

8. Shell Programming and Scripting

repetition calculation

cat mylist First_NAME Gender Mike M Sara F Raya M Sara F Fibi F Mike M Mike M Micheal M can someone please help me to get a script to cacluate the number of repetions for each (First name... (3 Replies)
Discussion started by: Sara_84
3 Replies

9. UNIX for Beginners Questions & Answers

Repetition in a particular interval

Suppose I have a word which is repeating in a string continuously. I have a set of intervals. Then how do I find the number occurrences of that word in those intervals and their location of occurrences. For example - Suppose there is a huge string anfie.......sirn of 10000 letters. Now the word... (2 Replies)
Discussion started by: ANKIT ROY
2 Replies

10. Windows & DOS: Issues & Discussions

Adding same value to variables in does each repetition of command

So, I have this command: mkdir rolled for %%x in (*gif) do convert %%x -roll +2+6 %%x|move %%x rolled I'd like to have the +2 and +6 accumulate here. In each new gif tackled, it should increase by the amount: +2 (for x) and +6 (for y) Is this possible? I'm on Windows, DOS. (0 Replies)
Discussion started by: pasc
0 Replies
sendfilev(3EXT) 					    Extended Library Functions						   sendfilev(3EXT)

NAME
sendfilev - send a file SYNOPSIS
cc [ flag... ] file... -lsendfile [ library... ] #include <sys/sendfile.h> ssize_t sendfilev(int fildes, const struct sendfilevec *vec, int sfvcnt, size_t *xferred); DESCRIPTION
The sendfilev() function attempts to write data from the sfvcnt buffers specified by the members of vec array: vec[0], vec[1], ... , vec[sfvcnt-1]. fildes is a file descriptor to a regular file or to a AF_NCA, AF_INET, or AF_INET6 family type SOCK_STREAM socket that is open for writing. This function is analogous to the writev() system call. See writev(2). However, instead of sending out chunks of data, sendfilev() can read input data from data buffers or file descriptors. The following is the sendfilevec structure: typedef struct sendfilevec { int sfv_fd; /* input fd */ uint_t sfv_flag; /* Flags. see below */ off_t sfv_off; /* offset to start reading from */ size_t sfv_len; /* amount of data */ } sendfilevec_t; #define SFV_FD_SELF (-2) To send a file, open the file for reading. Point sfv_fd to the file descriptor returned as a result. See open(2). sfv_off should contain the offset within the file. sfv_len should have the length of the file to be transferred. The xferred parameter is updated to record the total number of bytes written to out_fd. The sfv_flag field is reserved and should be set to zero. To send data directly from the address space of the process, set sfv_fd to SFV_FD_SELF. sfv_off should point to the data, with sfv_len con- taining the length of the buffer. PARAMETERS
The sendfilev() function supports the following parameters: fildes A file descriptor to a regular file or to a AF_NCA, AF_INET, or AF_INET6 family type SOCK_STREAM socket that is open for writing. For AF_NCA, the protocol type should be zero. vec An array of SENDFILEVEC_T, as defined in the sendfilevec structure above. sfvcnt The number of members in vec. xferred The total number of bytes written to out_fd. RETURN VALUES
Upon successful completion, sendfilev() returns total number of bytes written to out_fd. Otherwise, it returns -1, and errno is set to indicate an error. xferred contains the amount of data successfuly transferred, which can be used to discover the error vector. ERRORS
EAFNOSUPPORT The implementation does not support the specified address family for socket. EPROTOTYPE The socket type is not supported. EBADF The fildes argument is not a valid descriptor open for writing or an sfv_fd is invalid or not open for reading. EACCES The process does not have appropriate privileges or one of the files pointed by sfv_fd does not have appropriate permissions. EPIPE The fildes argument is a socket that has been shut down for writing. EIO An I/O error occurred while accessing the file system. EFAULT The vec argument points to an illegal address. EFAULT The xferred argument points to an illegal address. EINVAL The sfvcnt argument was less than or equal to 0. One of the sfv_len in vec array was less than or equal to 0, or greater than the file size. An sfv_fd is not seekable. EAGAIN Mandatory file or record locking is set on either the file descriptor or output file descriptor if it points at regular files. O_NDELAY or O_NONBLOCK is set, and there is a blocking record lock. An attempt has been made to write to a stream that cannot accept data with the O_NDELAY or the O_NONBLOCK flag set. USAGE
The sendfilev() function has a transitional interface for 64-bit file offsets. See lf64(5). EXAMPLES
The following example sends 2 vectors, one of HEADER data and a file of length 100 over sockfd. sockfd is in a connected state, that is, socket(), accept(), and bind() operation are complete. #include <sys/sendfile.h> . . . int main (int argc, char *argv[]){ int sockfd; ssize_t ret; size_t xfer; struct sendfilevec vec[2]; . . . vec[0].sfv_fd = SFV_FD_SELF; vec[0].sfv_flag = 0; vec[0].sfv_off = "HEADER_DATA"; vec[0].sfv_len = strlen("HEADER_DATA"); vec[1].sfv_fd = open("input_file",.... ); vec[1].sfv_flag = 0; vec[1].sfv_off = 0; vec[1].sfv_len = 100; ret = sendfilev(sockfd, vec, 2, &xfer); . . . } ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
open(2), writev(2), libsendfile(3LIB), sendfile(3EXT), socket(3SOCKET), attributes(5) SunOS 5.10 19 Apr 2004 sendfilev(3EXT)
All times are GMT -4. The time now is 05:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy