|
|
вернуться в форумWA4 Послано bilol 25 сен 2009 20:27 I can't find my mistake, if someone know suggest me my mistake please: #include <iostream> #include <string> #include <string.h> using namespace std; char* reverse(char* str) { char* temp = new char[strlen(str) + 1]; int i, n = strlen(str); if(str[n-1] == ',' || str[n-1] == '-' || str[n-1] == '.' || str[n-1] == '?' || str[n-1] == ':' || str[n-1] == ';') { temp[n-1] = str[n-1]; n-=1; } for(i = 0; i<n; i++) { temp[i] = str[n - i - 1]; } if(n == strlen(str) - 1) temp[i+1] = '\0'; else temp[i] = '\0'; return temp; } int main() { string *as = new string[1000]; int i = 0;
#ifndef ONLINE_JUDGE freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); #endif while(getline(cin,as[i++])) {
}
for(int j = 0; j<i-1; j++) { const char* str = as[j].c_str(); char* ch = new char[strlen(str) + 1]; strcpy(ch,str); //ch[strlen(str)] = '\0'; //cout<<ch; char* temp = strtok(ch," "); cout<<reverse(temp); while(temp != NULL) { temp = strtok(NULL," "); if(temp != NULL) cout<<" "<<reverse(temp); } cout<<endl; }
return 0; } |
|
|