当前位置: 首页>>代码示例>>C++>>正文


C++ Scanner::nextLine方法代码示例

本文整理汇总了C++中Scanner::nextLine方法的典型用法代码示例。如果您正苦于以下问题:C++ Scanner::nextLine方法的具体用法?C++ Scanner::nextLine怎么用?C++ Scanner::nextLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Scanner的用法示例。


在下文中一共展示了Scanner::nextLine方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: readPapers

	void readPapers(int papers, Scanner scanIn) {
		int paper;
		for (paper = 1; paper <= papers; paper++) {
			String paperAuthors;

			paperAuthors = scanIn.nextLine();
			#ifdef DEBUG
				printf("paper #%d %s\n", paper, paperAuthors);
			#endif

			Author authors[] = new Author[Author.MAX_PAPER_AUTHORS];
			int authorsIndex = 0;

			Pattern p = Pattern.compile("\\s*(\\S*)[,]\\s*(\\S*)[,:]");
			Matcher m = p.matcher(paperAuthors);
			while (m.find()) {
				String lname = m.group(1);
				String fname = m.group(2);

				if (debug) {
					printf("\t'%s' => '%s', '%s'\n", paperAuthors, lname, fname);
				}

				authors[authorsIndex] = Author.find(fname, lname);
				if (authors[authorsIndex] == null) {
					if (lname.length() == 0 || fname.length() == 0) {
						continue;
					}
					authors[authorsIndex] = new Author(fname, lname);
				}
				authorsIndex++;
			}

			for (int i = 0; i < authorsIndex; i++) {
				for (int j = 0; j < authorsIndex; j++) {
					authors[i].publicouCom(authors[j]);
				}
			}
		}
	}
开发者ID:luis-puhl,项目名称:algoritmos-avancados,代码行数:40,代码来源:main.cpp

示例2: main

int main(int argc, char** varg)
{
  if(argc < 4)//this is how to use this
  {
    cerr << "usage: cmd file1 file2 output" << endl;
    return 1;
  }

  //these are for holding each files occurances of strings, or lack thereof
  set<WORD> file1, file2;
  
  //Java like Scanner object
  Scanner scan;
  //open the file given as argument 1
  scan.openFile(varg[1]);
  //to the first file 'file1' we will add each string that is in there
  //for the first occurance we set count at 1, and increment as needed
  //to the second file 'file2' we will add each string from 'file1'
  //and set the count to 0
  while(scan.hasMoreData())
  {
    ScanLine line;
    line.openString(scan.nextLine());
    while(line.hasMoreData())
    {
      string nxt_token = line.next();
      nxt_token = Utils::trimBlanks(nxt_token);

      //add elements to 'file2' once with count 0
      if(file2.count(nxt_token) == 0)
      {
	WORD f_two;
	f_two.token = nxt_token;
	f_two.count = 0;
        file2.insert(f_two);
      }
      //add first occurance to file1 with count 1
      if(file1.count(nxt_token) == 0)
      {
	WORD f_one;
	f_one.token = nxt_token;
	f_one.count = 1;
        file1.insert(f_one);
      }
      else
      {
	//replace the word with a word of equal token and +1 count
	set<WORD>::iterator it = file1.find(WORD(nxt_token));
	int ct = it->count;
	ct++;
	file1.erase(it);
	WORD replace;
	replace.token = nxt_token;
	replace.count = ct;
	file1.insert(replace);
      }
    }
  }
  scan.close();//close file1

  cout << "++++++++++++++++++++++++++++++++++++++++++++++++" << endl;

  scan.openFile(varg[2]);//open file2

  //to the second file 'file2' we will add each word we find, or
  //increment as needed if it occurred in the first file
  //if a string occurs in 'file2' that doesn't exist in 'file1'
  //we will add any token to 'file1' list from 'file2' list and set count to 0
  while(scan.hasMoreData())
  {
    ScanLine line;
    line.openString(scan.nextLine());
    while(line.hasMoreData())
    {
      string nxt_token = line.next();
      nxt_token = Utils::trimBlanks(nxt_token);
      
      //if the word doesn't already exist in 'file1' add it with count 0
      if(file1.count(nxt_token) == 0)
      {
	WORD f_two;
	f_two.token = nxt_token;
	f_two.count = 0;
        file1.insert(f_two);
      }
      //add the first occurance of a word to 'file2' with count 1
      if(file2.count(nxt_token) == 0)
      {
	WORD f_one;
	f_one.token = nxt_token;
	f_one.count = 1;
        file2.insert(f_one);
      }
      else
      {
	//replace the word with a word of equal token and +1 count	
	set<WORD>::iterator it = file2.find(WORD(nxt_token));
	int ct = it->count;
	ct++;
	file2.erase(it);
//.........这里部分代码省略.........
开发者ID:bflick,项目名称:ocrcomp,代码行数:101,代码来源:Compare.cpp

示例3: UvaErdo

	void UvaErdo() {
		int scenarios, papers = 0, names = 0;
		int scenario;

		Scanner *scanIn = new Scanner();
		String s = scanIn->nextLine();
		scenarios = Integer->parseInt(s->trim());
		for (scenario = 1; scenario <= scenarios; scenario++) {
			printf("Scenario %d\n", scenario);

			String nextLine = scanIn->nextLine();
			String s2[] = nextLine->split(" ");
			int i = 0;
			for (; s2[i] != null; i++) {
				try {
					papers = Integer.parseInt(s2[i].trim());
					#ifdef DEBUG
						printf("\tConverted '%s' to %d\n", s2[i].trim(), papers);
					#endif
					break;
				} catch (NumberFormatException e) {
				}
			}
			i++;
			for (; i < s2.length; i++) {
				try {
					names = Integer.parseInt(s2[i].trim());
					#ifdef DEBUG
						printf("\tConverted '%s' to %d\n", s2[i].trim(), names);
					#endif
					break;
				} catch (NumberFormatException e) {
				}
			}
			#ifdef DEBUG
				printf("\tConverted '%s' to %d papers and %d names\n", nextLine, papers,
						names);
			#endif

			readPapers(papers, scanIn);

			#ifdef DEBUG
				printf("Scenario %d\n", scenario);
			#endif

			List<Entry<String, Author>> theMap = new ArrayList<Map.Entry<String, Author>>(names);
			Set<Author> targets = new TreeSet<Author>();

			readCases(names, scanIn, theMap, targets);

			if (Author.erdosPtr != null) {
				Author.erdosPtr.process(targets);
				#ifdef DEBUG
					printf("Author::erdosPtr not null\n");
				#endif
			}

			for (Entry<String, Author> it : theMap) {
				Author a = it.getValue();
				String bigname = it.getKey();
				if (a == null) {
					printf("%s infinity\n", bigname);
				} else {
					int d = a.depht;
					if (d <= 0 && Author.erdosPtr != a) {
						printf("%s, %s infinity\n", a.lname, a.fname);
					} else {
						printf("%s, %s %d\n", a.lname, a.fname, d);
					}
				}
			}

			theMap.clear();
			Author.freeMemory();
		}
	}
开发者ID:luis-puhl,项目名称:algoritmos-avancados,代码行数:76,代码来源:main.cpp


注:本文中的Scanner::nextLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。