因为就做了4道,这里解析就四道了
其他题目不会做,求高手解答啊!!!
B - Who's in the Middle
Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
如题这是一个找中位数的题目,而题中又给出了n为奇数。所以只要弄个数组,排个序,把中间的数输出就行了!下面是c++代码
- #include<iostream>
- using namespace std;
- int main()
- {
- int a[10000],n,i,t,flag=1;
- cin>>n;
- for(i=0;i<n;i++)
- cin>>a[i];
- while(flag)
- {
- flag=0;
- for(i=0;i<n-1;i++)
- if(a[i]>a[i+1])
- {
- t=a[i];
- a[i]=a[i+1];
- a[i+1]=t;
- flag=1;
- }
- }
- cout<<a[(n-1)/2]<<endl;
- return 0;
- }
C - Bank Interest
Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
题目意思就是我们小时候常做的存钱求存了n年以后本金是多少。于是我们用一个循环,s=s*(100+r)/100.0来表示因为它要求不四舍五入,所以用(100+r)/100.0。下面是c++代码
- #include<iostream>
- using namespace std;
- int main()
- {
- int r,m,y,i;
- double s;
- cin>>r>>m>>y;
- s=m;
- for(i=0;i<y;i++)
- s=s*(100+r)/100.0;
- cout<<int(s)<<endl;
- return 0;
- }
D - Joseph
Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u
这道题真不会做,试了好久还是错,求高手指教!!!
E - Spell checker
Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
这个题目就是判断字符是否相等,判断也就那么几种情况,1.不删不补 2.删除任意r个 3.增加任意r个
下面为c++代码:
- #include<iostream>
- using namespace std;
- const int LEN = 18;
- const int MAX_MAP_LEN = 10010;
- class String
- {
- public:
- char string[LEN];
- int size;
- void getSize()
- {
- size = strlen(string);
- }
- };
- inline int kin_strcmp(String a,String b)
- {
- int i;
- for(i=0;i<b.size;i++)
- {
- if(*(a.string+i) != *(b.string+i)) return i;
- }
- return i;
- }
- int changeone_strcmp(String a,String b)
- {
- int i,count=0;
- int loc=b.size;
- for(i=0;i<b.size;++i)
- {
- if(*(a.string+i) != *(b.string+i))
- {
- loc = i;
- if(count++>2)
- return -1;
- }
- }
- return loc;
- }
- inline bool changeOne(String a,String b)
- {
- int loc;
- char i;
- loc = changeone_strcmp(a,b);
- if(loc<0) return false;
- for(i='a'; i<='z'; i++)
- {
- *(b.string+loc)=i;
- if(strcmp(a.string, b.string )==0){
- return true;
- }
- }
- return false;
- }
- inline bool deleteOne(String a,String b)
- {
- int i;
- char fir[LEN];
- for(i=0; i<b.size; i++)
- {
- *fir='\0';
- strncat(fir,b.string,i);
- strcat(fir,b.string+i+1);
- if(strcmp(a.string, fir )==0)
- {
- return true;
- }
- }
- return false;
- }
- bool InsertOne(String a,String b)
- {
- int i;
- char fir[LEN];
- int loc = kin_strcmp(a,b);
- for(i='a'; i<='z'; i++)
- {
- *fir='\0';
- strncat(fir,b.string,loc);
- *(fir+loc)=i;
- *(fir+loc+1)='\0';
- strcat(fir,b.string+loc);
- if(strcmp(a.string, fir )==0)
- {
- return true;
- }
- }
- return false;
- }
- int main()
- {
- int top = 0,i;
- String map[MAX_MAP_LEN];
- String str;
- bool isFirstOne;
- while(scanf("%s",map[top].string),map[top].string[0]!='#')
- {
- map[top++].getSize();
- }
- while(scanf("%s",str.string),str.string[0] != '#')
- {
- isFirstOne = true;
- str.getSize();
- for(i=0; i<top; ++i)
- {
- if(strcmp(str.string,map[i].string)==0)
- {
- printf("%s is correct\n",str.string);
- break;
- }
- }
- if(i<top) continue;
- for(i=0; i<top; ++i)
- {
- if(str.size==map[i].size)
- {
- if(changeOne(str,map[i]))
- {
- // cout<<endl<<"**"<<map[i]<<endl;
- if(isFirstOne == true){
- printf("%s:",str.string);
- isFirstOne = false;
- }
- printf(" %s",map[i].string);
- }
- } else
- if(str.size==map[i].size-1)
- {
- if(deleteOne(str,map[i]))
- {
- if(isFirstOne == true)
- {
- printf("%s:",str.string);
- isFirstOne = false;
- }
- printf(" %s",map[i].string);
- }
- }
- else
- if(str.size==map[i].size+1)
- {
- if(InsertOne(str,map[i]))
- {
- if(isFirstOne == true)
- {
- printf("%s:",str.string);
- isFirstOne = false;
- }
- printf(" %s",map[i].string);
- }
- }
- }
- if(isFirstOne)
- {
- printf("%s:",str.string);
- isFirstOne = false;
- }
- cout<<endl;
- }
- return 0;
- }
F - Triangle Wave
Crawling in process... Crawling failed Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
这道题就是排数阵,只要题意理解正确,解答起来应该不难,只要几个循环,题目就做出来了。重要的是那三个数的含义。第一个数表示有几组数,第二个数表示最大数,第三个数表示一组数显示几个。下面为c++代码:
- #include<iostream>
- using namespace std;
- int main()
- {
- int a,b[10000],c[10000],i,j,k,l;
- cin>>a;
- for(i=0;i<a;i++)
- cin>>b[i]>>c[i];
- for(i=0;i<a-1;i++)
- {
- for(l=0;l<c[i]-1;l++)
- {
- for(j=1;j<=b[i];j++)
- {
- for(k=0;k<j;k++)
- cout<<j;
- cout<<endl;
- }
- for(j=b[i]-1;j>=1;j--)
- {
- for(k=0;k<j;k++)
- cout<<j;
- cout<<endl;
- }
- cout<<endl;
- }
- for(j=1;j<=b[i];j++)
- {
- for(k=0;k<j;k++)
- cout<<j;
- cout<<endl;
- }
- for(j=b[i]-1;j>=1;j--)
- {
- for(k=0;k<j;k++)
- cout<<j;
- cout<<endl;
- }
- cout<<endl;
- }
- for(l=0;l<c[i]-1;l++)
- {
- for(j=1;j<=b[i];j++)
- {
- for(k=0;k<j;k++)
- cout<<j;
- cout<<endl;
- }
- for(j=b[i]-1;j>=1;j--)
- {
- for(k=0;k<j;k++)
- cout<<j;
- cout<<endl;
- }
- cout<<endl;
- }
- for(j=1;j<=b[i];j++)
- {
- for(k=0;k<j;k++)
- cout<<j;
- cout<<endl;
- }
- for(j=b[i]-1;j>=1;j--)
- {
- for(k=0;k<j;k++)
- cout<<j;
- cout<<endl;
- }
- return 0;
- }
阅读(3346) | 评论(0) | 转发(0) |