Skip to content

Instantly share code, notes, and snippets.

@allen501pc
Created April 18, 2012 11:24
Show Gist options
  • Save allen501pc/2412980 to your computer and use it in GitHub Desktop.
Save allen501pc/2412980 to your computer and use it in GitHub Desktop.
反轉議程委員表,把它轉換為 Name, Review No 1~Review No. n.
/* Author: Allen ([email protected])
* Date: 2012/04/18 18:30
* Goal: 反轉委員表,把它轉換為 Name, Review No 1~Review No. n.
*/
#include <iostream>
#include <fstream>
#include <string>
#include <iterator>
#include <map>
using namespace std;
int main(int argc, char * argv[])
{
set<string> NameSet;
char arrName[256];
multimap<string,int> InvertList;
fstream MyFile;
MyFile.open("test.csv",ios::in);
int Index = 1;
while(MyFile.getline(arrName,255))
{
char * ptrName;
ptrName=strtok(arrName,",");
InvertList.insert(pair<string,int>(ptrName,Index));
ptrName = strtok(NULL,",");
InvertList.insert(pair<string,int>(ptrName,Index));
ptrName = strtok(NULL,",");
InvertList.insert(pair<string,int>(ptrName,Index));
++Index;
}
MyFile.close();
char targetName[36]="";
strcpy(targetName,(*(InvertList.begin())).first.c_str());
bool isFirst = true;
for(multimap<string,int>::iterator it = InvertList.begin();it!=InvertList.end();++it)
{
if(strcmp(targetName,(it->first).c_str())!=0)
{
cout << endl;
isFirst=true;
strcpy(targetName,(it->first).c_str());
}
if(isFirst)
{
cout << targetName << ",";
isFirst = false;
}
cout << it->second << ",";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment