<h1 style="margin: 0px 0px 0.5em; padding: 0px; border: 0px; font-family: 'Droid Sans', Verdana, 'Microsoft YaHei', Tahoma, sans-serif; font-size: 3em; font-weight: normal; font-stretch: inherit; line-height: 1em; vertical-align: baseline; color: rgb(17, 17, 17); background-color: rgb(250, 250, 250);"></h1><h1 style="margin: 0px 0px 0.5em; padding: 0px; border: 0px; font-family: 'Droid Sans', Verdana, 'Microsoft YaHei', Tahoma, sans-serif; font-size: 3em; font-weight: normal; font-stretch: inherit; line-height: 1em; vertical-align: baseline; color: rgb(17, 17, 17); background-color: rgb(250, 250, 250);">1010. 一元多项式求导 (25)</h1><div id="problemInfo" class="rfloat" style="margin: 0px; padding: 2px; border: 1px solid rgb(221, 221, 221); font-family: 'Droid Sans', Verdana, 'Microsoft YaHei', Tahoma, sans-serif; font-stretch: inherit; line-height: 18px; vertical-align: baseline; float: right; text-align: center; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);"><div class="limit" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline;"><div class="key" style="margin: 0px; padding: 0px 20px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; background-color: rgb(221, 221, 221);">时间限制</div><div class="value" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline;">400 ms </div></div><div class="limit" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline;"><div class="key" style="margin: 0px; padding: 0px 20px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; background-color: rgb(221, 221, 221);">内存限制</div><div class="value" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline;">65536 kB </div></div><div class="limit" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline;"><div class="key" style="margin: 0px; padding: 0px 20px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; background-color: rgb(221, 221, 221);">代码长度限制</div><div class="value" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline;">8000 B </div></div><div class="checker" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline;"><div class="key" style="margin: 0px; padding: 0px 20px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; background-color: rgb(221, 221, 221);">判题程序</div><div class="value" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline;"><span title="纯文本对比" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline;">Standard</span></div></div></div><div id="problemContent" style="margin: 0px; padding: 0px; border: 0px; font-family: 'Droid Sans', Verdana, 'Microsoft YaHei', Tahoma, sans-serif; font-stretch: inherit; line-height: 18px; vertical-align: baseline; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);"><p style="margin-top: 0px; margin-bottom: 1.5em; padding-top: 0px; padding-bottom: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline;">设计函数求一元多项式的导数。</p><p style="margin-top: 0px; margin-bottom: 1.5em; padding-top: 0px; padding-bottom: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline;"><strong>输入格式:</strong>以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过1000的整数)。数字间以空格分隔。</p><p style="margin-top: 0px; margin-bottom: 1.5em; padding-top: 0px; padding-bottom: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline;"><strong>输出格式:</strong>以与输入相同的格式输出导数多项式非零项的系数和指数。数字间以空格分隔,但结尾不能有多余空格。注意“零多项式”的指数和系数都是0,但是表示为“0 0”。</p><strong>输入样例:</strong><pre style="margin-top: 1.5em; margin-bottom: 1.5em; padding: 0px; border: 0px; font-family: 'Droid Sans Mono', Consolas, 'Courier New', monospace; font-size: 1em; font-stretch: normal; line-height: 1.5; vertical-align: baseline; overflow: auto;">3 4 -5 2 6 1 -2 0输出样例:
12 3 -10 1 6 0
#include<iostream> #include<vector> #include<algorithm> using namespace std; int main() { vector<int> data; int temp; while(cin>>temp) { data.push_back(temp); } int length = data.size(); if ((length == 2) && (data[length - 1]==0)) { cout<<"0"<<" "<<"0"<<endl; return 0; } if (length == 0) { cout<<"0"<<" "<<"0"<<endl; return 0; } if (data[length - 1] == 0) { data.erase(data.end() - 2, data.end()); } length = data.size(); if (length >= 2) { for (vector<int>::iterator start = data.begin(); start != data.end() - 2; start += 2) { cout<<*start * *(start + 1)<<" "<<*(start + 1) - 1<<" "; } cout<<data[length - 2] * data[length - 1]<<" "<<data[length - 1] - 1<<endl; } return 0; }
原文地址:http://blog.csdn.net/u011233383/article/details/43538351