|
题目:有一些日期,在文件abc.txt中,后面*号的表示要加班的日期,试汇总所有每个月25号的天数,如果是加班日,则该天乘2.
abc.txt
Oct. 25 2003
Oct. 26 2000
Sep. 12 2003*
Juy. 25 2002*
App. 25 2004
//=======================
#include<iostream>
#include<sstream>
#include<vector>
#include<fstream>
#include<algorithm>
using namespace std;
//-----------------------
int main(){
int sum=0;
ifstream in("abc.txt");
typedef vector<vector<char> > Mat;
Mat m;
for(string s;getline(in,s);){
vector<char> b;
istringstream sin(s);
for(char a;sin>>a;)
b.push_back(a);
m.push_back(b);}
for(int i=0;i<m.size();i++) {
string a,c;
a = m[i][1];
c = m[i][2];
a.find("25")!= -1 ?"sum+=1":"";
c.find("*")!= -1 ?"sum+=2":"";
}
cout<<sum;
}//=======================
老警告我...Comparing signed and unsigned values in function main()
...请高手指点指点... |
|