|
|
back to boardWa#16 who can help me to find my bug?.Here is my program,thanks. Posted by Hrayr 1 Jul 2011 19:14 #include <iostream> #include <cstring> #include <fstream> #include <string> using namespace std; char ch[20]; int x[200]; struct data { int d,m,y; }; struct mas { data d1,d2,d3; }; mas a[200]; int n; void work(int i,int t) { char day[10]; char month[10]; char year[15]; day[0]=ch[0]; day[1]=ch[1]; month[0]=ch[3]; month[1]=ch[4]; year[0]=ch[6]; year[1]=ch[7]; year[2]=ch[8]; year[3]=ch[9]; if (t==1) { a[i].d1.d=atoi(day); a[i].d1.m=atoi(month); a[i].d1.y=atoi(year); } else if (t==2) { a[i].d2.d=atoi(day); a[i].d2.m=atoi(month); a[i].d2.y=atoi(year); } else { a[i].d3.d=atoi(day); a[i].d3.m=atoi(month); a[i].d3.y=atoi(year); } } bool nahanj(int year) // this checks if the year has 366 or 365 days { if (year%400==0) return 1; if (year%100==0) return 0; if (year%4==0) return 1; else return 0; } int get_year(int year) // this returns how many days has the year { if (nahanj(year)) return 366; return 355; } int get_month(int a,int year) // this returns how many days has the month { if (a==4 || a==6 || a==9 || a==11) return 30; if (a==2 && nahanj(year)) return 29; if (a==2 && !nahanj(year)) return 28; else return 31; } int get_life(int i0) // and this returns how many year lived the person { int i; int sum1(0),sum2(0),sum(0); for(i=1700;i<a[i0].d1.y;i++) sum1+=get_year(i); for(i=1;i<a[i0].d1.m;i++) sum1+=get_month(i,a[i0].d1.y); sum1+=a[i0].d1.d; for(i=1700;i<a[i0].d3.y;i++) sum2+=get_year(i); for(i=1;i<a[i0].d3.m;i++) sum2+=get_month(i,a[i0].d3.y); sum2+=a[i0].d3.d; sum=sum2-sum1; return sum; } int main() { //ifstream cin("input.txt"); int i,m(-1),pos(-1); cin>>n; for(i=0;i<n;i++) { cin>>ch; work(i,1); cin>>ch; work(i,2); cin>>ch; work(i,3); } for(i=0;i<n;i++) x[i]=get_life(i); for(i=0;i<n;i++) { if (x[i]>m) { m=x[i]; pos=i; } } cout<<pos+1<<endl; return 0; }
Edited by author 01.07.2011 19:17 Re: Wa#16 who can help me to find my bug?.Here is my program,thanks. Just trip: scanf( "%ld.%ld.%ld", &d, &m, &y ); |
|
|