觉得浮夸了四年,漠然发现原来是浮躁了四年!

浙大研究生复试

07年 Excel排序  http://acm.hdu.edu.cn/showproblem.php?pid=1862

想放松下,就来做做浙大的复试题,考的都是蛮基础的,可是各种陷阱有没有,接着就连着wa了N次,被虐有木有?

这题完全基本函数的应用,需熟悉sort、strcmp等函数和结构体,就ok了。

可是一定要看清啊!  当若干学生具有相同姓名或者相同成绩时,则按他们的学号递增排序。

还有按姓名的非递减序列排序,不是需要比个姓名的首个字符就可以的。

复制代码
View Code
 1 #include<iostream>
 2 #include<iomanip>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<cstdio>
 6 using namespace std;
 7 struct node{
 8     int num;
 9     char name[10];
10     int mark;
11 }s[100005];
12 bool cmp1(node a,node b)
13 {
14     return a.num<b.num;
15 }
16 bool cmp2(node a,node b)
17 {
18     if(strcmp(a.name,b.name)==0)
19         return a.num<b.num;
20     else
21     {
22         int t;//这里的处理一定要注意  
23      t=strcmp(a.name,b.name);//这里strcmp函数返回的 0,1,2 
24      if(t<0)//所以这里要处理一下
25          return true;
26      else
27          return false;
28     }
29 }
30 bool cmp3(node a,node b)
31 {
32     if(a.mark==b.mark)
33     return a.num<b.num;
34     else
35         return a.mark<b.mark;
36 
37 }
38 int n,c;
39 int main()
40 {
41      int i;
42      char str[100];
43      int flag=1;
44      while(cin>>n>>c)
45      {
46          getchar();
47          if(n==0)  break;
48          
49          for(i=0;i<n;i++)
50          {
51              gets(str);
52              sscanf(str,"%d %s %d",&s[i].num,s[i].name,&s[i].mark);
53          }
54          cout<<"Case "<<flag++<<":"<<endl;
55          if(c==1)
56          {
57              sort(s,s+n,cmp1);
58             for(i=0;i<n;i++)
59              {
60                 cout.width(6);//用控制格式符补齐6位数字
61                 cout.fill('0');
62                cout<<s[i].num;
63                cout<<" "<<s[i].name<<" "<<s[i].mark<<endl;
64              }
65          }
66          else if(c==2)
67          {
68              sort(s,s+n,cmp2);
69             for(i=0;i<n;i++)
70              {
71                 cout.width(6);
72                 cout.fill('0');
73                cout<<s[i].num;
74                cout<<" "<<s[i].name<<" "<<s[i].mark<<endl;
75              }
76          }
77          else
78          { sort(s,s+n,cmp3);
79              for(i=0;i<n;i++)
80              {
81                 cout.width(6);
82                 cout.fill('0');
83                cout<<s[i].num;
84                cout<<" "<<s[i].name<<" "<<s[i].mark<<endl;
85              }
86          }
87      }
88      return 0;
89 }
复制代码

 07年 最小长方形  http://acm.hdu.edu.cn/showproblem.php?pid=1859

好吧,研究生复试!呵呵。。。。。。

只不过代码有点挫奥!

复制代码
View Code
 1 #include<iostream>
 2 #include<cstring>
 3 using namespace std;
 4 int main()
 5 {
 6     int x1,x2,y1,y2;
 7     
 8     int x,y;
 9     while(1)
10     {x1=234;x2=-234;
11     y1=234;y2=-234;
12     int a,b;
13      cin>>a>>b;
14      if(a==0&&b==0)  break;
15         if(a<x1)
16             x1=a;
17         if(a>x2)
18             x2=a;
19         if(b<y1)
20             y1=b;
21         if(b>y2)
22             y2=b;
23      
24     while(cin>>x>>y&&(x!=0||y!=0))
25     {
26         
27         if(x<x1)
28             x1=x;
29         if(x>x2)
30             x2=x;
31         if(y<y1)
32             y1=y;
33         if(y>y2)
34             y2=y;
35     }
36     cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;
37     }
38     return 0;
39 }
40     
复制代码

 

 08年 魔咒词典 http://acm.hdu.edu.cn/showproblem.php?pid=1880

其实,C/C++的知识面还很匮乏,许多函数还用的不熟悉。本题完全属于字符串匹配,刚开始企图用map函数的,可是对map的了解有限,于是就有了下面这个胚胎级的代码.

复制代码
View Code
 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 using namespace std;
 5 struct node{
 6     char mz[25];
 7     char fun[85];
 8 }s[100005];
 9 int main()
10 {
11     char line[111];
12     int i;
13     i=0;
14     while(gets(line))
15     {
16         if(line[0]=='@') break;
17         int len=strlen(line);
18         int k=0;
19         int j;
20         for(j=1;line[j]!=']';j++)
21         {
22             s[i].mz[k++]=line[j];
23         }
24         strcpy(s[i].fun,line+j+2);
25         i++;
26     }
27     int num=i;
28     int n;
29     char q[100];
30     cin>>n;
31     getchar();
32     while(n--)
33     {
34         int flag=0;
35         gets(q);
36         if(q[0]=='[')
37         {
38             int len=strlen(q);
39             char real[100];
40             int k=0;
41             for(int j=1;q[j]!=']';j++)
42             {
43                 real[k++]=q[j];
44             }
45             real[k]='\0';
46             for(i=0;i<num;i++)
47             {
48                 if(strcmp(s[i].mz,real)==0)
49                 {
50                     puts(s[i].fun);
51                 //    cout<<endl;
52                     flag=1;break;
53                 }
54             }
55         }
56         else
57         {
58             for(i=0;i<num;i++)
59             {
60                 if(strcmp(s[i].fun,q)==0)
61                 {
62                     puts(s[i].mz);
63                 //    cout<<endl;
64                     flag=1;break;
65                 }
66                 
67             }
68         }
69         if(flag==0)
70             cout<<"what?"<<endl;
71     }
72     return 0;
73 }
复制代码

 08年 又一版A+B http://acm.hdu.edu.cn/showproblem.php?pid=1877

禁止的转换,唯一需要注意的是当两个数的和sum等于0,时特殊处理一下!为此,WA了两次。

复制代码
View Code
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 using namespace std;
 6 __int64 m,a,b;
 7 int ans[200];
 8 __int64 sum;
 9 int main()
10 {
11     while(scanf("%I64d",&m)&&m)
12     {
13 
14         scanf("%I64d%I64d",&a,&b);
15         sum=0;memset(ans,0,sizeof(ans));
16         int k=0;
17         sum=a+b;
18         if(sum==0)
19             cout<<"0"<<endl;
20         else
21         {
22     
23         while(sum)
24         {
25             ans[k++]=sum%m;
26             sum=sum/m;
27         }
28         for(int i=k-1;i>=0;i--)
29             cout<<ans[i];
30         cout<<endl;
31         }
32     }
33     return 0;
34 }
35 
36 
37         
复制代码

Post by heat_nan         @2012-03-16    20:12          


  

 

posted @   heat nan  阅读(240)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
点击右上角即可分享
微信分享提示